WSGI (python) how to get POST data from an HTML form?
Question: This is the HTML form that "gets" /1.wsgi

    
    
    <form action="/1.wsgi" method="get">
    <input type="text" name="one">
    <input type="submit" value="Send">
    </form>
    

this is my 1.wsgi script:

    
    
    from cgi import parse_qs
    import os
    
    def application(environ, start_response):
        o = parse_qs(environ['QUERY_STRING'])
        oo = o.get('one', [''])[0]
        start_response('200 OK', [('content-type', 'text/html')])
        yield oo
    

works very nicely, _BUT_ I would like to use `POST` method rather than `GET`.
I understand in html form `"get"` has to be changed to `"post"` but what
exactly must I do in the WSGI script?


Answer: A POST sends the encoded form data in the request body; read `CONTENT_LENGTH`
bytes from the `wsgi.input` stream:

    
    
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    
    request_body = environ['wsgi.input'].read(request_body_size)
    o = parse_qs(request_body)
    

This is assuming you are still using the default form encoding,
`application/x-www-form-urlencoded`.

