question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DefaultCredentialsError if project in env but not credentials

See original GitHub issue

We use a custom method to get credentials (we need to pass them in through env variables). I think that the library prevents us from using the GOOGLE_CLOUD_PROJECT env var - is that right?

Specifically: when initializing a client, the library attempts to find a default project (> /usr/local/lib/python2.7/dist-packages/google/cloud/_helpers.py(179)_determine_default_project()), and calls google.auth.default().

That function only uses explicit_project_id if it can find credentials:

    258     from google.auth.credentials import with_scopes_if_required
    259
    260     explicit_project_id = os.environ.get(
    261         environment_vars.PROJECT,
    262         os.environ.get(environment_vars.LEGACY_PROJECT))
    263
    264     checkers = (
    265         _get_explicit_environ_credentials,
    266         _get_gcloud_sdk_credentials,
    267         _get_gae_credentials,
    268         lambda: _get_gce_credentials(request))
    269
    270     for checker in checkers:
    271         credentials, project_id = checker()
# credentials are always none if there are no credentials in environment...
    272         if credentials is not None:
    273             credentials = with_scopes_if_required(credentials, scopes)
# ...so this line is never reached, and explicit_project_id isn't used
    274             effective_project_id = explicit_project_id or project_id
    275             if not effective_project_id:
    276                 _LOGGER.warning(
    277                     'No project ID could be determined. Consider running '
    278                     '`gcloud config set project` or setting the %s '
    279                     'environment variable',
    280                     environment_vars.PROJECT)
    281             return credentials, effective_project_id
    282
--> 283     raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)

Is this intended? We can pull GOOGLE_CLOUD_PROJECT manually and pass that in, though the auto-fallback to the env var is a bit of convenience

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
theacodescommented, Feb 14, 2018
0reactions
max-sixtycommented, Feb 14, 2018

Thank you! That def resonates

Read more comments on GitHub >

github_iconTop Results From Across the Web

google.auth.exceptions.DefaultCredentialsError - Stack Overflow
Your need to set an environment variable for GOOGLE_APPLICATION_CREDENTIALS. You can add this in your code by adding in the following lines:
Read more >
google-auth 1.17.0 documentation
Implements application default credentials and project ID detection. ... DefaultCredentialsError: if the file is in the wrong format or is missing.
Read more >
Google Auth Library for Python. - Read the Docs
If no credentials are found, DefaultCredentialsError will be raised. Example: import google.auth credentials, project_id = ...
Read more >
How Application Default Credentials works | Authentication
If ADC does not find credentials it can use in either the GOOGLE_APPLICATION_CREDENTIALS environment variable or the well-known location for Google Account ...
Read more >
Resolving 'Application Default Credentials' error ... - NEX Softsys
Resolve an 'Application Default Credentials' error when accessing GCP resources ... 'The Application Default Credentials are not available' or 'Environment ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found