[mod_python] POSTed form fields?

Gregory Trubetskoy grisha at modpython.org
Thu Aug 17 09:05:24 EST 2000


In other words, something like:

import cgi

len = int(req.headers_in["content-length"])
form_data = cgi.parse_qs(req.read(len))

Should do it. Dr. Timouchouk is right - if you're POSTing large files
(50K+), then you should check the size returned by read() and read() again
if it wasn't all.

The next release will make this unnecessary - read() will return all there
was to read. It will also follow the apache Timeout directive.

If you're handy with CVS - you can get that code right now from the
sourceforge CVS server.

--
  Gregory (Grisha) Trubetskoy
       grisha at modpython.org

On Thu, 17 Aug 2000, Dr. L.A. Timochouk wrote:

> The request object does not contain parsed (or even unparsed) POSTed
> fields, so you need to read and parse them yourself:
> 
> (1) get the total length of the POSTed data from the "Content-length"
>     header (available through the "headers_in" table in the request
>     object);
> 
> (2) read the data in using the "read" method on the req object; NB:
>     in mod_python 2.4.1, "read" can return a shorter data chunk than
>     requested ("short read"); a patch had been submitted which
>     rectifies the problem; alternatively you can do multiple "read"s
>     until you get the whole length of your data;
> 
> (3) then you can parse the contents splitting it into key=value
>     pairs separated by "&"s. There are some subtleties like multiple
>     fields with the same name, file submission by POST,etc, to take
>     care about.
> 
> Hope it will help,
> 
> Leonid Timochouk
> Computing Laboratory
> University of Kent at Canterbury
> England
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
> 





More information about the Mod_python mailing list