Getting Python to mimic a CGI form submission using GET method

Alex Martelli aleaxit at yahoo.com
Wed Nov 1 18:20:00 EST 2000


"Colin Meeks" <colin at programmedintegration.com> wrote in message
news:YX0M5.11340$78.3340614 at news3.rdc1.on.home.com...
> > > Does anybody know how I can do a CGI form submission using a get
method
> > > and that allows me to process the results all in Python.  I can do one
> using a
> > > POST no problems.  If I replace the POST with a GET I don't get
> anything.
> >
> > Are you using the cgi module on the Python side...?
>
> No I'm using the httplib module, constructing a header and then capturing
> the result.

The CGI standard sanctions different ways to pass form data
when POST or GET are used.  The cgi module takes care,
among other things, of receiving and decoding the form data --
but that is on the server side (for a Python-written cgi script),
while it seems you're trying to work on the client-side, right?

The most likely mishap may have to do with the way you
are constructing the URL you GET (it's in the URL that form
data are included on GET).  Are you remembering to
concatenate to the script's URL a ? and then the
urllib.urlencode of the dictionary of the form data you're
sending...?

If you think you're sending exactly the same form-data
with either GET or POST, try -- e.g. with the CGI HTTP
server that's included with the standard Python
distribution: run cgi.py yourself as your cgi script,
it will respond with a very complete list of the data
available to the receiving script.  There must be some
differences between what you're sending via POST vs
via GET -- from the output of cgi.py, run as the cgi
script responding to either method, you can find and
analyze the differences, and hopefully determine what
went wrong.


Alex






More information about the Python-list mailing list