从Python客户端访问后端API

时间:2023-02-13 23:08:01

I want to access my Endpoints API on Google app engine from a Python client. I am using Google APIs Python client library. My API doesn't require any authentication and so I am using the code provided in this link

我想从Python客户端访问Google App引擎上的我的Endpoints API。我正在使用Google API Python客户端库。我的API不需要任何身份验证,因此我使用此链接中提供的代码

https://cloud.google.com/endpoints/docs/frameworks/python/access_from_python

https://cloud.google.com/endpoints/docs/frameworks/python/access_from_python

But I am getting this error:

但是我收到了这个错误:

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.

Which credentials I need to set to make the API call successfully?

我需要设置哪些凭据才能成功调用API?

1 个解决方案

#1


2  

We needed to Create a service account key in GCP console. More details are here: https://cloud.google.com/storage/docs/reference/libraries

我们需要在GCP控制台中创建服务帐户密钥。有关详细信息,请访问:https://cloud.google.com/storage/docs/reference/libraries

Then in the python code we added:

然后在python代码中我们添加了:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/SERVICE_KEY.json"

After that I can access my endpoint API without authentication.

之后,我无需身份验证即可访问我的端点API。

#1


2  

We needed to Create a service account key in GCP console. More details are here: https://cloud.google.com/storage/docs/reference/libraries

我们需要在GCP控制台中创建服务帐户密钥。有关详细信息,请访问:https://cloud.google.com/storage/docs/reference/libraries

Then in the python code we added:

然后在python代码中我们添加了:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/SERVICE_KEY.json"

After that I can access my endpoint API without authentication.

之后,我无需身份验证即可访问我的端点API。