1
votes

I'm currently testing google cloud storage json API to list my bucket objects. I have followed these instructions to create Default Credentials. And also I have enabled gcs json API on my project's dashborad.. But still it shows ApplicationDefaultCredentialsError error..

$ 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
below answer does the job.. Is there any other way to make the variable available on runtime?Avinash Raj

1 Answers

1
votes

I found the way for passing env variable to python at runtime. I have to run,

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