Client-side code submits an object (in the POST request body) or query string (if using GET method) via ajax request to a python cgi script. Please note that the object/query string parameters are not coming from a
<form> or <isindex>.
How can I retrieve these parameters from within the server-side python script using standard library modules (e.g., cgi)?
Thanks very much
EDIT:
@codeape: Thanks, but wouldn't that work only for submitted forms? In my case, no form is being submitted, just an asynchronous request.
Using your script, len(f.keys()) returns 0 if no form is submitted! I can probably recast the request as a form submission, but is there a better way?
You use the cgi.FieldStorage class. Example CGI script:
#! /usr/bin/python
import cgi
from os import environ
import cgitb
cgitb.enable()
print "Content-type: text/plain"
print
print "REQUEST_METHOD:", environ["REQUEST_METHOD"]
print "Values:"
f = cgi.FieldStorage()
for k in f.keys():
print "%s: %s" % (k, f.getfirst(k))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With