Search notes:

WSGI: Serving POST requests (reading data from wsgi.input)

The data that a user agent sends to a WSGI compliant webserver by means of a POST request can be read by the WSGI application from the object that is stored in environ['wsgi.input'], as demonstrated in the code below:
def application(environ, start_response):

    if environ['PATH_INFO'] == '/':

       start_response( '200 OK', [('Content-Type', 'text/html; charset=utf-8')])

       return ['''
         <h1>Create POST request with some data</h1>
         <form action="/post-request" method="post">
           Text one: <input type="text" name="text-one" value="Héllo"><br>
           Text two: <input type="text" name="text-two" value="Wörld"><p>
           <input type="submit" value="Go!">
         </form>
        '''.encode('utf-8')]

    elif environ['REQUEST_METHOD'] == 'POST':

       start_response( '200 OK', [('Content-Type', 'text/plain; charset=utf-8')])

       return [
           f'POST request for {environ["PATH_INFO"]}, data received in body shown below.\n\n'.encode('utf-8'),
           environ['wsgi.input'].read()
       ]

    else:

       start_response( '200 OK', [('Content-Type', 'text/plain; charset=utf-8')])

       return [
         f'PATH_INFO:      {environ["PATH_INFO"     ]}\n'.encode('utf-8'),
         f'REQUEST_METHOD: {environ["REQUEST_METHOD"]}'  .encode('utf-8')
       ]

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199315, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/PEP/3333/POST-requests_wsgi-input(63): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78