I'm trying to get the very basics of POST communication with Python. My question is what is the most fundamental way and what is a simple package to process a raw POST message received by the server. The raw result contains these lines with some code after it, with in between the real POST content... So how would I parse this into say a dict... {key: value,...} and what is this very basic process called?
I have a simple piece of code that I run with uwsgi in the following matter:
sudo uwsgi --socket myapp2.sock --plugins /usr/lib/uwsgi/plugins/python3_plugin.so --module wsgi --chmod-socket=664 --chown-socket=www-data:www-data --uid www-data --gid www-data
curl -F 'somekeyname=somevalue or file content' localhost?anotherkey=anothervalue
this results in:
Hello There!
--------------------------e72349b67358ae71
Content-Disposition: form-data; name="somekeyname"
somevalue or file content
--------------------------e72349b67358ae71--
anotherkey=anothervalue
This is the code I have:
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
try:
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
request_body = environ.get('wsgi.input', b'').read(request_body_size).decode('utf-8')
get_values = environ.get('QUERY_STRING', '')
return [("Hello There!\n\n" + request_body + "\n\n\n\n" + get_values).encode('utf-8')]