GAE: remote_api and Application Default Credential

2019-04-10 05:41发布

Since today i've been using remote_api (python) to access the datastore on GAE.

I usually do remote_api_shell.py -s <mydomain>.

Today I tried and it fails, the error is:

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.

I cannot understand why it asks me that.

the wole output is this

stefano@~/gc$ remote_api_shell.py -s ....
Traceback (most recent call last):
  File "/usr/local/bin/remote_api_shell.py", line 133, in <module>
    run_file(__file__, globals())
  File "/usr/local/bin/remote_api_shell.py", line 129, in run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/remote_api_shell.py", line 157, in <module>
    main(sys.argv)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/remote_api_shell.py", line 153, in main
    appengine_rpc.HttpRpcServer)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/remote_api_shell.py", line 74, in remote_api_shell
    secure=secure)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 734, in ConfigureRemoteApiForOAuth
    credentials = client.GoogleCredentials.get_application_default()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/oauth2client/oauth2client/client.py", line 1204, in get_application_default
    return GoogleCredentials._get_implicit_credentials()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/oauth2client/oauth2client/client.py", line 1194, 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.

2条回答
乱世女痞
2楼-- · 2019-04-10 06:02
  1. Go to the Developers Console under API Manager>>Credentials (currently at https://console.developers.google.com/apis/credentials?project=<<<Your App Id>>>).
  2. Click on the service account, and then on a button that is labeled: "Generate new JSON Key".
  3. A file will be downloaded, save it in a secure place.
  4. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to point to the file you saved before you run remote_api_shell.py
查看更多
祖国的老花朵
3楼-- · 2019-04-10 06:11

The solution is to run gcloud auth login in the shell and give the grant again

查看更多
登录 后发表回答