CGI POST problem was: How to read POSTed data
Dan Perl
danperl at rogers.com
Sun Feb 6 01:53:56 EST 2005
<and-google at doxdesk.com> wrote in message
news:1107659974.048175.221770 at z14g2000cwz.googlegroups.com...
> Dan Perl wrote:
>
>> how is a multipart POST request parsed by CGIHTTPServer?
>
> It isn't; the input stream containing the multipart/form-data content
> is passed to the CGI script, which can choose to parse it or not using
> any code it has to hand - which could be the 'cgi' module, but not
> necessarily.
>
>> Where is the parsing done for the POST data following the header?
>
> If you are using the 'cgi' module, then cgi.parse_multipart.
Thanks, at least I was right not to find that in the CGIHTTPServer and
BaseHTTPServer code. So I have to use that instead of FieldStorage? I was
expecting FieldStorage to encapsulate all that for all the cases, POST with
multipart/form-data being just a special case.
I took a brief look at cgi.parse_multipart and I still have to figure out
how to provide the fp argument. Any code examples anywhere? All the
examples I have found were using only FieldStorage:
http://www.cs.virginia.edu/~lab2q/lesson_7/
http://www.devshed.com/index2.php?option=content&task=view&id=198&pop=1&page=0&hide_js=1
http://gnosis.cx/publish/programming/feature_5min_python.html
http://mail.python.org/pipermail/edu-sig/2001-June/001368.html
BTW, I also tried the example in the last link and that doesn't work either,
with similar results/problems as my script. I think all those examples are
a few years old, has something changed since then?
>> As a side note, I found other old reports of problems with cgi
>> handling POST requests, reports that don't seem to have had a
>> resolution.
>
> (in particular?)
I made the comment and now I have to back that up:
http://mail.python.org/pipermail/python-list/2002-February/thread.html#88686
http://mail.python.org/pipermail/python-list/2002-September/thread.html#124109
> FWIW, for interface-style and multipart-POST-file-upload-speed reasons
> I wrote an alternative to cgi, form.py
> (http://www.doxdesk.com/software/py/form.html). But I haven't found
> cgi's POST reading to be buggy in general.
I was quite careful in calling the code "fragile" and I am not normally the
kind of person to mince words. I would have said buggy if I meant that or I
could have used even worse words. But even the rationale behind the patch
that caused the bug I mentioned ("Remove dependencies on (deprecated) rfc822
and mimetools modules, replacing with email.") and even your calling this
part of the standard library "a bit crufty in places due to age" support my
view that this code needs work.
Besides, I am not happy at all with the idea of having to use
cgi.parse_multipart instead of FieldStorage. It seems a lot more low level
than I would like to even if it offers more control. I looked at your
form.py and you seem to address that. Sorry though, I will probably not use
it. Once I learn enough from the cgi module I will just move on to using a
framework like CherryPy.
Dan
More information about the Python-list
mailing list