Skip to content
Advertisement

Python: How to Use Requests Library to Access Flask RestPlus API hosted on Google App Engine?

I built a rest api using flask restplus and I tested it using the swagger documentation, and it seems to be fully functional and working just fine. I now want to test the API using the python requests library, but I’m getting the following error:

JavaScript

I imagine this is because I did not authorize using the credentials. I do have access to the service account credentials json file, but just wondering how I pass this into requests?

Code Example:

JavaScript

Thanks in advance.

Advertisement

Answer

I think the best way to accomplish this is using the google-auth library for python.

JavaScript

I suggest to create a service account, give it the role IAP-secured Web App User and then download the JSON key for that service account.

Go to API’s & Services > Credentials and copy the Client ID of the OAuth 2.0 client you want to use for your API.

Finally use this code snippet to make a request:

JavaScript

If you want to know more about google-auth check this.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement