Search code examples
pythongoogle-app-enginepython-requestsurllib3

Google Appengine: Requests Alternative


I have a non-GAE application/request-handler that uses the Python requests module in a to post an uploaded imaged via a POST request, as binary:

headers = {"MyAuth" : "xyz"}
r = requests.post(base_uri, data=open('0.jpg')), headers=headers)

The user uploads an image, the uploaded image is saved locally, opened for reading, then sent to a remote classifier pipeline via post request - this returns some JSON regarding the image features, which can then be returned to the user.

I need to implement this behaviour in a GAE app, but know that GAE has no traditional file system, so I will have to use StringIO:

data = ... #some jpg => str
headers = {"MyAuth" : "xyz"}
r = requests.post(base_uri, data=StringIO.StringIO(data), headers=headers)

How could I completely replace the requests module in this example in a GAE friendly way?

Many thanks.


Solution

  • Although probably not the best solution to this problem, I managed to get requests 2.3.0 to work in the GAE project with:

    pip install --target myproject/externals/ requests==2.3.0
    

    I can now use requests as I would normally.