On 27 nov, 15:13, [EMAIL PROTECTED] wrote: > On 26 nov, 23:22, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > > > > > On Nov 27, 12:21 am, [EMAIL PROTECTED] 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 > > 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 -- http://mail.python.org/mailman/listinfo/python-list