Shyam
Shyam

Reputation: 627

nginx does not forward POST data to uwsgi -- [UPDATE] flask does not read post data

I have a very peculiar problem with a very simple setup.

The setup has nginx web server deployed for serving some static pages. Also it has a backend uwsgi deamon for handling POST requests.

My nginx location configuration is as follows

#For handling POST Request
location  = / {
#              index index.html;
#               autoindex on;

                uwsgi_pass unix:/tmp/uwsgi.sock;
                include uwsgi_params;
}

#For handling static page requests under /custpages
location ^(/custpages).*(\.html) {

                autoindex off;

 }

When I deploy this server and issue post requests from my browser the nginx is not sending the POST data to uwsgi.

But interestingly , when I issue a standalone POST request using python requests, it works as expected.

I am wondering, whats wrong with the browser based POST request compared to the standalone request, as both are going through the nginx.

Any pointers ?

Thanks in advance

[UPDATE]

This seems to be an issue with uwsgi. For POST sent from python requests it returns the POST data as I can see the response bytes in the uwsgi log.

But for request sent from browser the response bytes is zero.

In both cases teh uwsgi is receiving the proper POST data from nginx so it seems this is something to do with uwsgi

[UPDATE 2]

Further update. This issue has nothing to do with nginx or uwsgi.

I am using python with the flask microframework for my server backend application and the problem is something like this.

I use the current request context objectto read POST data as follows data_string = request.data

Now , as it turns out, request.data is empty when the POST is issued from browser When POST is issued from python requests then request.data contains the proper POST data.

So , any flask nerds out there, plz help me with this

Upvotes: 2

Views: 3838

Answers (1)

Shyam
Shyam

Reputation: 627

This problem is due to an inherent behavior in flask framework which causes the POST data to not apprear in the current request context object.

See the following question for details and resolution.

Flask not getting any data from jQuery request data

Upvotes: 2

Related Questions