Apache & mod_python: I don't receive anything with POST method

Graham Dumpleton Graham.Dumpleton at gmail.com
Wed Nov 26 17:22:06 EST 2008


On Nov 27, 12:21 am, tengounpl... at gmail.com wrote:
> Hi,
>
> I'm using a simple form to make possible the users of our site upload
> files.
>
> <html>
>     <head><meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1"></head>
>     <body>
>     <form method="post" enctype="multipart/form-data" action="/ws/
> upload.py"/>
>         <input name="upfile" type="file" size="50"/><br>
>         <input type="submit" value="send"/>
>     </form>
>     </body>
> </html>
>
> The "upload.py" looks like this:
>
> from mod_python import apache, util;
>
> def index(req):
>     form = util.FieldStorage(req, keep_blank_values=1)
>     try:
>         # form is empty here
>         # return form --> I get "{}"
>         ufile = form.get('upfile', None)
>
>         if not form.has_key('upfile'):
>             return ":( No 'upfile' key"
>
>         # some checks. I never get beyond here
>
>         ufile = form['upfile']
>         if ufile.file:
>             return ufile.file.name
>         else:
>             return ":( It's not a file"
>     except Exception, e:
>         return 'Fail: ' + str(e)
>
> I'm getting an empty 'form'. No 'upfile' key at all. I've tried to add
> some other text fields but the result is the same: empty. If I use GET
> method with text fields, it works properly.
>
> Currently I'm using:
> Apache 2.2.9 (initially I used Apache 2.2.3 too)
> mod_python 3.3.1 (initially I used mod_python 3.2.10 too)
> Python 2.5.2

Which is the correct result for the code you are using.

The problem is that you appear to be using mod_python.publisher which
does its own form handling before you are even getting a chance, thus
it is consuming the request content.

For how to handle forms in mod_python.publisher see:

http://webpython.codepoint.net/mod_python_publisher_forms

Graham



More information about the Python-list mailing list