google-auth-library-python: Intermittent DefaultCredentialsError on GCE
Original issue: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/4358
After successful use of credentials, _ = google.auth.default()
, an application crashes when credentials cannot be detected:
...
File "/usr/local/lib/python2.7/dist-packages/google/cloud/client.py", line 212, in __init__
Client.__init__(self, credentials=credentials, _http=_http)
File "/usr/local/lib/python2.7/dist-packages/google/cloud/client.py", line 125, in __init__
credentials, _ = google.auth.default()
File "/usr/local/lib/python2.7/dist-packages/google/auth/_default.py", line 286, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.
/cc @dmho418
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 23 (11 by maintainers)
Commits related to this issue
- Add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping(). This one is adding same behaviour & tests for .get() method, as the proble... — committed to DaniilAnichin/google-auth-library-python by deleted user 5 years ago
- Add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping(). This one is adding same behaviour & tests for .get() method, as the proble... — committed to DaniilAnichin/google-auth-library-python by deleted user 5 years ago
- Add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping(). This one is adding same behaviour & tests for .get() method, as the proble... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- Add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping(). This one is adding same behaviour & tests for .get() method, as the proble... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- Add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping()n This one is adding same behaviour & tests for .get() method, as the proble... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- Add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping()n This one is adding same behaviour & tests for .get() method, as the proble... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- fix(google.auth.compute_engine.metadata): add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping() This one is adding same behaviour... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- fix(google.auth.compute_engine.metadata): add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping() This one is adding same behaviour... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- fix(google.auth.compute_engine.metadata): add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping() This one is adding same behaviour... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- fix(google.auth.compute_engine.metadata): add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping() This one is adding same behaviour... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- fix(google.auth.compute_engine.metadata): add retry to google.auth.compute_engine._metadata.get() Initial fix of issue #211 was done in CL #323, but only for .ping() This one is adding same behaviour... — committed to DaniilAnichin/google-auth-library-python by DaniilAnichin 5 years ago
- fix(google.auth.compute_engine.metadata): add retry to google.auth.compute_engine._metadata.get() (#398) Initial fix of issue #211 was done in CL #323, but only for .ping() This one is adding same b... — committed to googleapis/google-auth-library-python by DaniilAnichin 4 years ago
I would love to see a fix for this issue
I’m still seeing this error fairly regularly running on GAE flex for Python 3.6 with
google-auth==1.6.3
. Here’s the full stack trace:@GEverding the recommendation right now is to use a service account keyfile instead of relying on the GCE metadata service.
It’s possible that we could make retry failed connections to the metadata service, but I’m unsure on that at the moment.
We see this issue in our setup as well. Python script connecting to BQ and running hundreds of queries in rapid fire sequence. We’ll occasionally see:
A INFO:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable.
followed by a crash:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credential and re-run the application.
Also from @dmho418 (may be unrelated to this issue, but is probably the root cause):
@mike-seekwell Thanks for the call out! #323 merged a fix to retry the ping to the metadata server.
If you’re seeing this error, please upgrade to version 1.6.3 or greater.
Is this something that I’ll need to push up a keyfile with my flex deployment (as @vanpelt mentioned), or will it be fixed in the PR that was just linked?
@vanpelt yep, that is a completely acceptable approach.