In my app.yaml, a url is defined to be:
- url: /api/.*
script: main.app
login: admin
secure: always
I tried to the following code to talk to the api
import requests
def main():
r = requests.get("https://test.appspots.com/api/get_data", auth=('[email protected]', 'password'))
print r.status_code, r.text
if __name__ == '__main__':
main()
But authentication has failed and, judging from the output, I am redirect to a login page.
How can I use python to authenticate and access the url?
In the Google Cloud console, go to the Custom Domains tab of the App Engine Settings page. Click Add a custom domain. If your domain is already verified, the domain appears in the Select the domain you want to use section. Select the domain from the drop-down menu and click Continue.
To access the App Engine APIs Explorer tool, open up the navigation menu and select APIs & Services > Library. In the search bar, enter in App Engine and select the App Engine Admin API from the results list. Make sure that API is enabled, if not click Enable.
App Engine provides the gcloud app deploy command, which builds an image with your source code and deploys that image on App Engine. You can use the cloud-sdk image as a build step in your config file to invoke gcloud commands within the image.
login: admin
instructs Google App Engine to restrict URLs matching the given pattern to users who are authenticated with Google AND are Administrators of your Google App Engine project. There is no way to use standard HTTP Basic Authentication with this restriction. If you have a valid oAuth Bearer token you can pass it in the header in requests.get
to handle the required authentication.
See this article on appidentity for some possible options: https://cloud.google.com/appengine/docs/python/appidentity/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With