Skip to content Skip to sidebar Skip to footer

Flask Is Not Getting Any Post Data From A Request

Within our server we've got this piece a code calling a function inside my APP like this: data = urllib.urlencode( dict(api_key='a-key-goes-here') ) headers = { 'User-Agent' :

Solution 1:

But in other words, for a reason request.form is empty and it shouldn't.

I don't think you can infer this conclusion. What appears to be happening is you have a GET request with a POST header.

From the Python docs:

data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format.

You need to remove the header

"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"

when you are sending requests with an empty data structure, or just remove it alltogether (it will be added automatically by urllib when needed)

Post a Comment for "Flask Is Not Getting Any Post Data From A Request"