GAE:remote_api和Application Default Credentials

Ess*_*eTi 4 python google-app-engine google-cloud-datastore

从今天开始,我一直在使用remote_api(python)来访问GAE上的数据存储区.

我经常这样做remote_api_shell.py -s <mydomain>.

今天我尝试了它失败了,错误是:

oauth2client.client.ApplicationDefaultCredentialsError:应用程序默认凭据不可用.如果在Google Compute Engine中运行,则可以使用它们.否则,必须定义环境变量GOOGLE_APPLICATION_CREDENTIALS,指向定义凭证的文件.有关 详细信息,请参阅 https://developers.google.com/accounts/docs/application-default-credentials.

我不明白为什么它问我.

wole输出就是这个

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.
Run Code Online (Sandbox Code Playgroud)

Ess*_*eTi 5

解决方案是gcloud auth login在shell中运行并再次提供授权


gae*_*123 5

  1. 转到API管理器>>凭据下的开发者控制台(当前位于https://console.developers.google.com/apis/credentials?project=<<<Your App Id>>>)。
  2. 单击服务帐户,然后单击标记为“生成新的JSON密钥”的按钮。
  3. 将下载文件,并将其保存在安全的地方。
  4. 将环境变量GOOGLE_APPLICATION_CREDENTIALS设置为指向您在运行remote_api_shell.py之前保存的文件