Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting form data ?
#1
How can I get input data from a form via post without using any framework ?
Reply
#2
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'' ?
Reply
#3
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?

Werkzeug parses the incoming data under the following situations:
  • you access either form, files, or stream and the request method was POST or PUT.
  • if you call parse_form_data().

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.
Reply
#4
(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 werkzeug
Quote:When does Werkzeug Parse? Werkzeug parses the incoming data under the following situations:
  • you access either form, files, or stream and the request method was POST or PUT.
  • if you call parse_form_data().
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.

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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Post HTML Form Data to API Endpoints Dexty 0 1,410 Nov-11-2021, 10:51 PM
Last Post: Dexty
  POST request with form data issue web scraping hoff1022 1 2,691 Aug-14-2020, 10:25 AM
Last Post: kashcode
  Get form data JohnnyCoffee 0 2,108 Jan-29-2020, 01:39 PM
Last Post: JohnnyCoffee
  How to send data from remotely hosted HTML form to Pi sajid 2 2,581 Jun-27-2019, 10:28 PM
Last Post: sajid
  Django - Retrieve form data justantest 0 2,846 May-23-2019, 11:47 AM
Last Post: justantest

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020