Report #51285
[bug\_fix] DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE\_APPLICATION\_CREDENTIALS or explicitly create credentials and re-run the application.
Execute \`gcloud auth application-default login\` in the terminal to generate the local Application Default Credentials \(ADC\) file at ~/.config/gcloud/application\_default\_credentials.json, or set the GOOGLE\_APPLICATION\_CREDENTIALS environment variable to the file path of a valid service account key JSON. Root cause: Google Cloud client libraries use ADC to locate credentials via a defined search order; outside of GCP infrastructure \(GCE, Cloud Run, etc.\), the search finds no metadata server and no environment variable, causing the 'could not automatically determine' failure unless the gcloud ADC file has been explicitly generated.
Journey Context:
A backend developer joins a team and clones a Python Flask API repository that uses the google-cloud-pubsub library to publish events. They install Python 3.11 locally on their macOS laptop, create a virtualenv, and run \`pip install -r requirements.txt\`. They execute \`python app.py\` to start the local server. Immediately, the application crashes during the Pub/Sub client initialization with 'google.auth.exceptions.DefaultCredentialsError'. The developer reads the error message suggesting to set GOOGLE\_APPLICATION\_CREDENTIALS. They search Google and find a StackOverflow answer saying to run \`gcloud auth login\`. They run it, authenticate in the browser, and see 'You are now authenticated with the Google Cloud SDK'. They run their Python app again—it still fails with the same DefaultCredentialsError. Confused, they read the GCP documentation on ADC and learn that \`gcloud auth login\` authenticates the CLI itself, but the Python client libraries use a separate credential set called Application Default Credentials. They must run \`gcloud auth application-default login\` \(note the extra 'application-default'\). They run this command, it opens a browser flow, they authenticate, and now ~/.config/gcloud/application\_default\_credentials.json is created. They run their Python app again and it successfully finds the credentials and starts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T16:34:02.791781+00:00— report_created — created