0

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.

2 Answers 2

1

Commonly used module for making HTTP requests on app engine is urlfetch, it is available in the default runtime via google.appengine.api.urlfetch. Supposedly urllib2 and/or urllib3 are also options, but I have not used those myself so I can't say for sure.

You can also install requests in your app engine directory and upload it with the project, but I find that a bit of a hassle, since requests has its own dependencies that you will need to include as well.

Also see Using the Requests python library in Google App Engine

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Tim. I took a look at urlfetch and it got me most of the way, however the binary upload, whilst it did upload the data and return a 200, the classifier could not extract any usable features from the data. Bizarre, I'm clearly missing something very simple. Unfortunately time is against me on this project, so I managed to get requests 2.3.0 working in production.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.