Can Python Requests library be used on Google App Engine?
this is now possible, I got it working using this combination of workarounds in appengine_config.py:
# Step 1: first add requests and requests-toolbelt to your requirements.txt (or however you install them via pip)
# Step 2: in appengine_config.py add the following snippet:
# see https://cloud.google.com/appengine/docs/python/issue-requests#issuing_an_http_request
import requests
import requests_toolbelt.adapters.appengine
# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt.adapters.appengine.monkeypatch()
# also monkey patch platform.platform() from https://code.google.com/p/googleappengine/issues/detail?id=12982
import platform
def patch(module):
def decorate(func):
setattr(module, func.func_name, func)
return func
return decorate
@patch(platform)
def platform():
return 'AppEngine'
Install the requests-toolbelt
library:
https://github.com/sigmavirus24/requests-toolbelt
For App Engine it could be something like: pip install requests-toolbelt -t lib
(See: https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_library)
Then add:
from requests_toolbelt.adapters import appengine
appengine.monkeypatch()
In your main.py
or equivalent.
Edit: this solution is now part of the official documentation: https://cloud.google.com/appengine/docs/python/issue-requests#issuing_an_http_request
(in the REQUESTS
tab)
Yes. On Google Appengine (version 1.9.18) requests version 2.3.0 works IN PRODUCTION (but not on SDK) if you have billing enabled, which enables sockets support.
Update: As of 31 Jan 2017 Requests is working in production with version 2.9.1 in production. However, it's not working with Google cloud SDK 141.0.0
requests on the Appengine SDK fails with all https:// requests:
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
requests version 2.4.1 fails in production with:
File "distlib/requests/adapters.py", line 407, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
requests version 2.5.1 fails in production with:
File "distlib/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
requests version 2.3.0 works in production, but may cause problems with Debians removed SSLv3 support in the SDK (requests 2.3.0 comes with its own now outdated urllib3). As workaround it is possible to delete the line containing PROTOCOL_SSLv3 in the source of request's urllib3 copy.
'module' object has no attribute 'PROTOCOL_SSLv3'
Info on sockets support: https://cloud.google.com/appengine/docs/python/sockets/
Not yet but hopefully very soon. Support for GAE is being worked on - see issue #498 (App Engine Fixes).
Requests uses urllib3 which in turn uses httplib which is supported on GAE as a wrapper for urlfetch API. Although urllib3 uses some modules not available on GAE this usage is deliberately made optional so that urllib3 can be used on GAE.