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

T

tengounplanb

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

Thanks

Best regards,
León
 
G

Graham Dumpleton

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
 
T

tengounplanb

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

Hi,

I should get a non-empty "form".

With the following html

<html>
<head><meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"></head>
<body>
<form method="get" action="/ws/upload.py"/>
<input type="text" name="some_text" size="50"/><br>
<input type="submit" value="enviar"/>
</form>
</body>
</html>

....and the following "upload.py":

from mod_python import util, apache

def index(req):
form = util.FieldStorage(req, keep_blank_values=1)
try:
some_text = form.get('some_text', None);
return form.items
except Exception, e:
return 'Fail: ' + str(e)

....I get (writting "Python" in the text box)

[('some_text', Field('some_text', 'Python'))]

So, I have a "form" with a non-empty structure of (key, value), and
I'm able to get the value I'm looking for:

....
some_text = form.get('some_text', None) # It's not empty anymore
....

Thanks

León
 
T

tengounplanb

On Nov 27, 12:21 am, (e-mail address removed) 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:

Graham

Hi,

I should get a non-empty "form".

With the following html

<html>
    <head><meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"></head>
    <body>
    <form method="get" action="/ws/upload.py"/>
        <input type="text" name="some_text" size="50"/><br>
        <input type="submit" value="enviar"/>
    </form>
    </body>
</html>

...and the following "upload.py":

from mod_python import util, apache

def index(req):
    form = util.FieldStorage(req, keep_blank_values=1)
    try:
        some_text = form.get('some_text', None);
        return form.items
    except Exception, e:
        return 'Fail: ' + str(e)

...I get (writting "Python" in the text box)

[('some_text', Field('some_text', 'Python'))]

So, I have a "form" with a non-empty structure of (key, value), and
I'm able to get the value I'm looking for:

...
some_text = form.get('some_text', None) # It's not empty anymore
...

Thanks

León

I got an alternative solution here
http://codepoint.net/index.php/topic,118.msg507.html#msg507

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top