Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python requests on Google App Engine not working for HTTPS

I'm using python-request on Google App Engine and it's not working as expected for HTTPS. Let's see an example:

import requests
requests.get('https://www.digitalocean.com')

That line works perfectly if I execute it in a terminal. Response is 200 OK (without redirects).

However, if I execute it on GAE a TooManyRedirects error is raised. Trying to figure out what's the problem I execute with allow_redirects=False and I can see that the response is a redirect (301) which points to the same url!!! ('location' header value is 'https://www.digitalocean.com'). This obviously (when allow_redirect=True) happens over and over again until the TooManyRedirects error is raised.

So it seems that python-requests is not working on GAE for HTTPS (I've tested with several URL). However HTTP works perfectly.

Any idea about what's happening?

Thanks in advance.

like image 828
Curro Avatar asked Feb 06 '14 14:02

Curro


People also ask

Does Python requests use https?

Requests verifies SSL certificates for HTTPS requests, just like a web browser. SSL Certificates are small data files that digitally bind a cryptographic key to an organization's details.

Does Google App Engine support Python 3?

The Python 3 runtime supports Python 3.7, Python 3.8, Python 3.9, and Python 3.10 and uses the latest stable release of the version that is specified in your app. yaml file. App Engine automatically updates to new patch release versions, but it will not automatically update the minor version.


1 Answers

Downgrading to requests==2.1.0 worked for me.

Having an up-to-date urllib3 is important for resolving an unrelated bug (import pwd, as I recall).

Hopefully App Engine fixes this soon, as requests won't.

EDIT:

I think you can also patch this in the latest requests by commenting lines 161-175 in sessions.py. Untested.

like image 100
rattray Avatar answered Sep 29 '22 13:09

rattray