我想从 Python 客户端访问我在 Google 应用引擎上的 Endpoints API。我正在使用 Google APIs Python 客户端库。 我的 API 不需要任何身份验证,因此我使用此链接中提供的代码
https://cloud.google.com/endpoints/docs/frameworks/python/access_from_python
但是我收到了这个错误:
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/discovery.py", line 358, in build_from_document
credentials = _auth.default_credentials()
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_auth.py", line 42, in default_credentials
credentials, _ = google.auth.default()
File "/usr/local/lib/python3.5/dist-packages/google/auth/_default.py", line 306, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically
determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credentials and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.
我需要设置哪些凭据才能成功调用 API?
请您参考如下方法:
我们需要在 GCP 控制台中创建服务帐户 key 。更多细节在这里: https://cloud.google.com/storage/docs/reference/libraries
然后在我们添加的python代码中:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/SERVICE_KEY.json"
之后,我无需身份验证即可访问我的端点 API。
