Getting form data ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Getting form data ? (/thread-22287.html) |
Getting form data ? - JohnnyCoffee - Nov-06-2019 How can I get input data from a form via post without using any framework ? RE: Getting form data ? - JohnnyCoffee - Nov-06-2019 using the example below I get the output : ws_body = int(environ['CONTENT_LENGTH']) ws_input = environ['wsgi.input'].read(ws_body) ws_print = ws_input status = '200 OK' headers = [('Content-type', 'text/html; charset=utf-8')] ws_output(status, headers) return [str(ws_print).encode('utf-8')] output-> b'' ? RE: Getting form data ? - snippsat - Nov-07-2019 As i mention before look at how other has done this. As these task task can be hard to figure out at low WSGI level using the specification Doc in PEP 333 or PEP 3333 Werkzeug is a thin layer above WSGI,and stuff Flask is build on. Form Data Parsing werkzeug Quote:When does Werkzeug Parse? In there example you see raw data that comes in from a form. data = '--foo\r\nContent-Disposition: form-data; name="test"\r\n'\ '\r\nHello World!\r\n--foo--'If i make own parser as a quick test,not looking how they have made the parser. >>> import re >>> >>> r = re.search(r"name=\"\w+\"(.*?)--", data, re.DOTALL) >>> r.group(1).strip() 'Hello World!'Regex is common tool to use when parsing other Parsing In Python: Tools And Libraries. PyParsing -- A Python Parsing Module. RE: Getting form data ? - JohnnyCoffee - Nov-07-2019 (Nov-07-2019, 02:03 PM)snippsat Wrote: As i mention before look at at how other has done this. As these task task can be hard to figure out at low WSGI level using the specification Doc in PEP 333 or PEP 3333 Form Data Parsing werkzeugQuote:When does Werkzeug Parse? Werkzeug parses the incoming data under the following situations:In there example you see raw data that comes in from a form. Too bad this is a puzzle it would be interesting for python language itself to provide a native function within wsgiref to handle this somewhat similar issue as the request_uri () function for accessing url data. Could you think of something like request_form () or request_input () to gain access to data sent by forms? |