Can Python Requests library be used on Google App Engine?

Posted on

Question :

Can Python Requests library be used on Google App Engine?

Can I use Requests on Google App Engine? I think this library is perfect to create a REST client.

Answer #1:

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/", 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/", 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:

Answered By: cat

Answer #2:

Install the requests-toolbelt library:

For App Engine it could be something like: pip install requests-toolbelt -t lib


Then add:

from requests_toolbelt.adapters import appengine

In your or equivalent.

Edit: this solution is now part of the official documentation:
(in the REQUESTS tab)

Answered By: Eyal Levin

Answer #3:

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.

Answered By: Piotr Dobrogost

Answer #4:

this is now possible, I got it working using this combination of workarounds in

# Step 1: first add requests and requests-toolbelt to your requirements.txt (or however you install them via pip)
# Step 2: in add the following snippet:

# see
import requests
import requests_toolbelt.adapters.appengine

# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.

# also monkey patch platform.platform() from
import platform

def patch(module):
    def decorate(func):
        setattr(module, func.func_name, func)
        return func
    return decorate

def platform():
    return 'AppEngine'
Answered By: jcjones1515

Answer #5:

No, in a more recent post, the developers say they do not support GAE because it’s too different from python.

Answered By: Ann Kilzer

Answer #6:

To fix up requests to work with Google App Engine but also allow my application to run outside of GAE, I added the following code:

    from google.appengine.api import urlfetch
    from requests_toolbelt.adapters import appengine
except ImportError:
Answered By: remeika

Answer #7:

Yes you can use the requests module.
GCP does not support the use of Requests library out of the box. So we will have to make some tweeks to make it work.
In order to deploy an application on the Google App Engine, we need to make a main python flask app resides) and app.yaml(configuration file needed to run it in GCP).
Here is a sample code for the app.yaml file for python 2.7 environment

runtime: python27
api_version: 1
threadsafe: true

- url: /.*
  redirect_http_response_code: 301

- name: flask
  version: 0.12

Now we need to configure the requests library to use URLfetch internally.
To use requests, we’ll need to install both requests and requests-toolbelt using the vendoring instructions. (
Basically we need to install our custom libraries.

  1. Create a directory to store your third-party libraries, such as lib/
    mkdir lib
  2. Upload the requests and requests-toolbelt libraries from your system or download them directly into the lib folder created in earlier step.
  3. Use pip (version 6 or later) with the -t flag to copy the libraries into the folder you created in the previous step. For example:
    pip install -t lib/ (pip install -t lib/ requests)
  4. Create a file named in the same folder as your app.yaml file.
  5. Edit the file and provide your library directory to the vendor.add() method.
    Sample file

    from google.appengine.ext import vendor
    # Add any libraries install in the "lib" folder.
  6. Once installed, use the requests_toolbelt.adapters.appengine module to configure requests to use URLFetch.
    Copy the below code to the start of your file

    import requests
    from requests_toolbelt.adapters import appengine


Now we can easily use the requests library to make get/post requests.
Test your app: --port=<port number> app.yaml
Answered By: Jatin Mahajan

Leave a Reply

Your email address will not be published. Required fields are marked *