Closed
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 --version
3.7.6 - pip version:
pip --version
20.0.2 google-cloud-storage
version:pip show google-cloud-storage
1.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!