When you haven’t gone through the Google Cloud Platform authentication process in your development environment, you might run into the following error message. In this blog post, I explain how you can solve it.
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.
Basically, the Cloud SDK is telling you that it’s not able to tell who you are when you are trying to access some GCP products. For this, we will create service account credentials and link them to your machine.
- Got to this link.
- If you are developing for Google Cloud Functions, or App Engine, then the App Engine default service account will suffice. Otherwise you will have to create a new account and specify rights for each GCP product.
- Finally, select JSON.
- A file should download now. For ease, rename it to ‘creds.json’.
- Put it in the directory of your development environment.
Finally, you should add the path to this file as an environment variable to your system.
PowerShell offers the following easy method to set the environment. If you want to variable to persist, you should read up on this article.
In the Windows Command Prompt you can do it as follows. You can replace set with setx to make it a persisting environment variable.
set GOOGLE_APPLICATION_CREDENTIALS "x:\xxxxx\xxx.json"
In UNIX systems, you use the export command. To make it persisting, read this detailed thread about the ways you can set environment variables.
Pingback: Web scraping with Google Cloud Functions, Pub/Sub, DataFlow & BigQuery — Roel Peters