Title: DefaultCredentialsError (only sometimes) in Google Compute Engine with docker · Issue #2995 · googleapis/google-cloud-python · GitHub
Open Graph Title: DefaultCredentialsError (only sometimes) in Google Compute Engine with docker · Issue #2995 · googleapis/google-cloud-python
X Title: DefaultCredentialsError (only sometimes) in Google Compute Engine with docker · Issue #2995 · googleapis/google-cloud-python
Description: Hello, I run a python script hourly, embedded in a docker container hosted on a Google Compute Engine instance. That script includes a step where I use python lib google.cloud.storage to upload files in google storage. I want to use the ...
Open Graph Description: Hello, I run a python script hourly, embedded in a docker container hosted on a Google Compute Engine instance. That script includes a step where I use python lib google.cloud.storage to upload fil...
X Description: Hello, I run a python script hourly, embedded in a docker container hosted on a Google Compute Engine instance. That script includes a step where I use python lib google.cloud.storage to upload fil...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/2995
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DefaultCredentialsError (only sometimes) in Google Compute Engine with docker","articleBody":"Hello,\r\n\r\nI run a python script hourly, embedded in a docker container hosted on a Google Compute Engine instance. That script includes a step where I use python lib google.cloud.storage to upload files in google storage.\r\n\r\nI want to use the default service account of the compute engine instance. As written in the [doc](https://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html), authentication should “just work”. And most of the time it does.\r\n\r\nYet I quite often get the error:\r\nFile \"/usr/local/lib/python2.7/dist-packages/google/auth/_default.py\", line 282, in default raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)\r\ngoogle.auth.exceptions.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.\r\n\r\nMy code:\r\n```\r\nimport google.auth\r\nfrom google.cloud import storage\r\n...\r\ncredentials, projectId = google.auth.default()\r\n# Next line raises sometimes the exception\r\nclient = storage.Client(projectId, credentials=credentials)\r\n...\r\n```\r\n\r\nWhen I run a python CLI from that same docker container, and call the `credentials, projectId = google.auth.default()`, I can see that the credentials are a `google.auth.compute_engine.credentials.Credentials object`, so I guess that the \"magic\" works even in a container (the doc does not explain how it works though).\r\n\r\nAny explanation on how to make it work, using the service account from the host compute instance ?\r\n\r\nMy env:\r\n* OS: ubuntu:16:04 (compute instance and docker instance)\r\n* python 2.7.12\r\n* google-cloud-storage==0.22.0, google-auth==0.5.0\r\n","author":{"url":"https://github.com/gjanvier","@type":"Person","name":"gjanvier"},"datePublished":"2017-02-10T09:11:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/2995/google-cloud-python/issues/2995"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:be49f069-2f6a-8fdd-83f3-01463acf887a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B404:15BB0E:51777F:6EB940:6A4D3E3A |
| html-safe-nonce | 322229488bf95636b40fe3aa3cd84153ed86a582b7ae2d6b296394e24a3264c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDA0OjE1QkIwRTo1MTc3N0Y6NkVCOTQwOjZBNEQzRTNBIiwidmlzaXRvcl9pZCI6IjUxOTgzNzQ5MzY0ODE5NzE3NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 27a63abb41f1b5bbae3002f0558f03ebf60cc5a5755c455a3fd0590cd2ecea52 |
| hovercard-subject-tag | issue:206743605 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/2995/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8df47fd85783bea786f35acb1af46913ed0e4b43d091be9af07f4032e16ed132/googleapis/google-cloud-python/issues/2995 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8df47fd85783bea786f35acb1af46913ed0e4b43d091be9af07f4032e16ed132/googleapis/google-cloud-python/issues/2995 |
| og:image:alt | Hello, I run a python script hourly, embedded in a docker container hosted on a Google Compute Engine instance. That script includes a step where I use python lib google.cloud.storage to upload fil... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gjanvier |
| hostname | github.com |
| expected-hostname | github.com |
| None | 92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fc8347865a14e2ec811533d68f929cf4e0ec19 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width