无法通过json API检索谷歌云存储桶对象

时间:2016-06-08 12:03:50

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

我目前正在测试google cloud storage json API以列出我的存储桶对象。我按照these说明创建了默认凭据。而且我在我的项目的dashborad上启用了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.

1 个答案:

答案 0 :(得分:1)

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

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