Report #10875
[bug\_fix] google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials
Run \`gcloud auth application-default login\` to populate the local ADC cache at \`~/.config/gcloud/application\_default\_credentials.json\`, or set the \`GOOGLE\_APPLICATION\_CREDENTIALS\` environment variable to the path of a service account key file. The GCP client libraries follow the Application Default Credentials \(ADC\) strategy, which searches for credentials in a strict order: first the environment variable, then a well-known local file populated by \`gcloud auth application-default login\`, then the metadata server \(only available inside GCP\). If none are found, the SDK throws this error.
Journey Context:
A developer writes a Python script using \`google-cloud-storage\` to upload files. The script works perfectly when deployed to a Compute Engine instance but fails on their local laptop with \`DefaultCredentialsError: Could not automatically determine credentials\`. The developer runs \`gcloud config list\` and confirms they are logged into the account, so they assume authentication is working. They search the error and learn that \`gcloud auth login\` only authorizes the gcloud CLI tool itself, while application code using GCP client libraries relies on a separate credential mechanism called Application Default Credentials \(ADC\). The developer checks \`~/.config/gcloud/application\_default\_credentials.json\` and finds the file missing or containing an expired token. They realize they never ran \`gcloud auth application-default login\`, which is required to populate that file with a valid OAuth token for application use. After running that command and authenticating via the browser, the JSON file is updated. The script now works because the client library finds the valid ADC file in the well-known path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:50:38.409937+00:00— report_created — created