【问题标题】:Can't retrieve google cloud storage bucket objects through json API无法通过 json API 检索谷歌云存储桶对象
【发布时间】:2023-03-26 14:20:01
【问题描述】:

我目前正在测试 google cloud storage json API 以列出我的存储桶对象。我已按照these 的说明创建默认凭据。而且我还在我的项目的仪表盘上启用了 gcs json API。但它仍然显示ApplicationDefaultCredentialsError 错误..

$ echo $GOOGLE_APPLICATION_CREDENTIALS
/home/gemini/Documents/foo-staging-dfab9cc17b65.json

$ python list_objects.py foo.staging.com
Traceback (most recent call last):
  File "list_objects.py", line 90, in <module>
    main(args.bucket)
  File "list_objects.py", line 78, in main
    print(json.dumps(get_bucket_metadata(bucket), indent=2))
  File "list_objects.py", line 50, in get_bucket_metadata
    service = create_service()
  File "list_objects.py", line 39, in create_service
    credentials = GoogleCredentials.get_application_default()
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 1398, in get_application_default
    return GoogleCredentials._get_implicit_credentials()
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 1388, in _get_implicit_credentials
    raise ApplicationDefaultCredentialsError(ADC_HELP_MSG)
oauth2client.client.ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

【问题讨论】:

  • 下面的答案可以完成这项工作。有没有其他方法可以使变量在运行时可用?

标签: google-app-engine google-cloud-storage


【解决方案1】:

我找到了在运行时将 env 变量传递给 python 的方法。我得跑了,

$ GOOGLE_APPLICATION_CREDENTIALS="/home/gemini/Documents/foo-staging-dfab9cc17b65.json" python list_objects.py <bucket-name>

【讨论】:

    猜你喜欢
    • 2018-05-11
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2020-02-15
    • 1970-01-01
    相关资源
    最近更新 更多