我能从文件中执行以下操作:
然而,如果我直接传递凭据,就会出现错误:
from google.cloud import storage
self.client = storage.Client.from_service_account_json('/Users/david/file-163219.json')
然而,如果我直接传递凭据,就会出现错误:
credentials_dict = {
"type": "service_account",
"project_id": "asdf-163219",
"private_key_id": "asdf2938492837498234",
}
credentials = service_account.Credentials.from_service_account_info(credentials_dict)
self.client = storage.Client(credentials=credentials)
但是我遇到了一个错误:
google.auth.exceptions.DefaultCredentialsError: 无法自动确定凭据。请设置GOOGLE_APPLICATION_CREDENTIALS或显式创建凭据并重新运行应用程序。有关更多信息,请参见https://developers.google.com/accounts/docs/application-default-credentials。
传递凭据字典的正确方法是什么?