Mod-python problem

Alan Kennedy alanmk at hotmail.com
Fri Mar 1 06:34:10 EST 2002


bp at sam.localdomain (Bob Parnes) wrote in message 

> The only trouble is that I had forgotten about my httpd.conf file. The 
> relevant lines are:
> 
> <Directory /var/www/modPython/test>
>   AddHandler python-program .py
>   PythonHandler mod_python.publisher
> </Directory>
> 
> This was the reason I used main() instead of handler(); in the url window I 
> typed in "test.py/main" and got the table but no response from FieldStorage().

> Are publisher and FieldStorage() incompatible, or am I misusing them? Knowing 
> what I know now, I can probably get along without publisher, but I am 
> accustomed to placing several scripts in one directory.

Bob,

Sorry, I didn't realise you were using the Publisher handler,
otherwise I wouldn't have gone and rewritten your code to work with a
completely different paradigm. And I was wondering how you were
getting results with something that just didn't look like it could
work %-) D'oh! Silly me.

Warning: I don't use the publisher handler, so I haven't tested any of
the stuff below!

Looking at the publisher handler documentation, section 6.1.3:
Publisher handler: Form data

http://www.modpython.org/live/mod_python-2.7.6/doc-html/node74.html

which says: 

"In the process of matching arguments, the Publisher handler creates
an instance of FieldStorage class. A reference to this instance is
stored in an attribute form of the Request object.

Since a FieldStorage can only be instantiated once per request, one
must not attept to instantiate FieldStorage when using the Publisher
handler and should use Request.form instead."

So it would appear to me that you shouldn't be trying to instantiate
the util.FieldStorage() class at all. Instead, you should be referring
to the already extant req.form attribute. So your main function should
change from this

def main(req):
    formDict = util.FieldStorage(req)
    cl = clTest()
    return cl.cltest(req, formDict)

to this

def main(req):
    cl = clTest()
    return cl.cltest(req, req.form)

As mentioned, I haven't tested any of this!

Hope this helps,

Al.



More information about the Python-list mailing list