-
Notifications
You must be signed in to change notification settings - Fork 167
Closed
Labels
api: storageIssues related to the googleapis/python-storage API.Issues related to the googleapis/python-storage API.type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
Description
Thanks for stopping by to let us know something could be better!
Environment details
- OS type and version: mac 10.14.6
- Python version:
python --version3.7.6 - pip version:
pip --version20.0.2 google-cloud-storageversion:pip show google-cloud-storage1.26.0
Steps to reproduce
Creating a Client using an explicit credentials object fails if the project parameter is not explicitly given. Since the project id should also be available from the credentials object, this should not be required of the caller.
The docs advertise an API where the project is not passed.
https://googleapis.dev/python/google-api-core/latest/auth.html#explicit-credentials
context: I'm trying to use GCS from heroku, where configuration is more easily done via env variables than the filesystem.
thanks!
Code example
import os
import json
from google.cloud import storage
from google.oauth2 import service_account
# env contains contents json keyfile
cred = os.environ['GCP_CRED']
c = json.loads(cred)
cred = service_account.Credentials.from_service_account_info(c)
# client = storage.Client(credentials=cred) # fails
client = storage.Client(project=c['project_id'], credentials=cred) # works
print(list(client.list_buckets()))output
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
Metadata
Metadata
Assignees
Labels
api: storageIssues related to the googleapis/python-storage API.Issues related to the googleapis/python-storage API.type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.