Search code examples
pythonpython-3.xgoogle-app-enginegoogle-cloud-endpoints

Accessing Backend APIs from Python Clients


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

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?


Solution

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

    Then in the python code we added:

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

    After that I can access my endpoint API without authentication.