Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing POST Data from WSGI

I can't seem to figure out how to access POST data using WSGI. I tried the example on the wsgi.org website and it didn't work. I'm using Python 3.0 right now. Please don't recommend a WSGI framework as that is not what I'm looking for.

I would like to figure out how to get it into a fieldstorage object.

like image 668
Evan Fosmark Avatar asked Feb 09 '09 23:02

Evan Fosmark


People also ask

What is WSGI entry point?

i would say WSGI application entry point is the wsgi.py script which is the Gate (stands also for Gateway) from apache into django app and vise versa. it is like browser < - > server < - > wsgi < - > django. without wsgi the server can serve (render) normal html files but not django app.

How does WSGI server work?

The server executes the web app and sends related information and a callback function to the app. The request is processed on the app side, and a response is sent back to the server utilizing the callback function. Sometimes there might be one or more WSGI middlewares between the server and the web app.

Why should I use WSGI?

WSGI is a standard described on PEP 3333 and basically, provides a standard interface between web applications written in Python and Webservers. That means, WSGI gives portability to your Python Web Application across many different Web Servers, without any additional configurations on your NGINX, Apache, etc.


1 Answers

Assuming you are trying to get just the POST data into a FieldStorage object:

# env is the environment handed to you by the WSGI server. # I am removing the query string from the env before passing it to the # FieldStorage so we only have POST data in there. post_env = env.copy() post_env['QUERY_STRING'] = '' post = cgi.FieldStorage(     fp=env['wsgi.input'],     environ=post_env,     keep_blank_values=True ) 
like image 139
Mike Boers Avatar answered Oct 02 '22 12:10

Mike Boers