cgi.FieldStorage not parsing query string

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Sat Jul 26 16:23:58 EDT 2003


Hi
I'm using cgi.FieldStorage to parse the HTTP request parameters
of a form submission. When the form is submitted using method="GET"
it correctly parses all form parameters.

However, if the form is submitted using "POST" (that's what I want!)
things go different. It only seems to parse the form parameters
that are sent *inside* the POST requst body.

Usually this is no problem, for instance when you POST it to the
following URL:   http://www.host.com/script.cgi

But if you add URL-encoded parameters, and use POST, the
URL-encoded parameters are lost:
http://www.host.com/script.cgi?extraarg=foobar
"extraarg" does not appear in the FieldStorage object.

Looking at the code it appears that FieldStorage is only parsing
the URL-encoded parameters (the QUERY_STRING) if the request
method is GET or HEAD, not when it is POST.

I'm not sure if this is correct. I think it is faulty behavior,
because if I do this with a Java Servlet, I *do* get the
URL-encoded parameters too. For the time being, I will call
cgi.parse_qsl myself and add the resulting list to the
FieldStorage list so that I *do* have all parameters.

Can somebody tell me if FieldStorage is wrong or that I
am mistaken here?

Thank you,
--Irmen de Jong





More information about the Python-list mailing list