Report #102995
[bug\_fix] Google Cloud DefaultCredentialsError: Could not automatically determine credentials
Point ADC to a credential source it can use. Locally, export GOOGLE\_APPLICATION\_CREDENTIALS to the path of a service-account key JSON, or run \`gcloud auth application-default login\` to create ~/.config/gcloud/application\_default\_credentials.json. In GCP-hosted environments, attach a service account to the GCE/Cloud Run/Cloud Function resource and grant it the needed IAM roles instead of using downloaded keys.
Journey Context:
A developer's Python script calling the Google Cloud Natural Language API worked in Cloud Shell but failed on their laptop with google.auth.exceptions.DefaultCredentialsError. They had downloaded credentials.json and ran \`set GOOGLE\_APPLICATION\_CREDENTIALS=...\` in CMD, then ran the script from VS Code's PowerShell terminal where the variable was unset. They tried renaming the file and moving it next to the script, but ADC does not search the working directory or infer a file name. The root cause is ADC's intentional design: it searches only GOOGLE\_APPLICATION\_CREDENTIALS, the gcloud ADC file path, or the attached-service-account metadata server, in that order. After setting the environment variable in the same shell as the script, or running \`gcloud auth application-default login\`, the client authenticated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:50:39.127628+00:00— report_created — created