Davin Boling
davin at wordpainter.net
Wed Mar 16 21:17:59 EST 2005
I've got an example that works correctly already. The problem is that in the larger handler that I've written, SOMETHING is breaking. I can't understand at all why req.read() returns nothing on a POST when it's the very first thing I assign to a variable. I'm about to go on a commenting crusade to narrow down where the problem is. This is my "from scratch" handler, which works correctly...just to show that I know how to handle a POST: from mod_python import apache def handler(req): head = """ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Debug</title> </head> <body> """ data = req.read() method = req.method req.content_type = "text/html" req.write(head + data + method + '</body></html>') return apache.OK Graham Dumpleton wrote: > Point whatever form you are using at: > > http://dscpl.user.openhosting.com/~grahamd/testing/details.py > > Eg: > > <form action="http://dscpl.user.openhosting.com/~grahamd/testing/details.py" method="post"> > <div> > Handle: > <input type="text" name="handle" maxlength="32"/> > > Password: > <input type="password" name="password" maxlength="32"/> > <input type="submit" name="login" value="Log in!"/> > </div> > </form> > > That URL will display various details about the request and for me at > least for a post form, yields something for req.read(). As an example, > try: > > http://dscpl.user.openhosting.com/~grahamd/testing/form.html > > You can see my code for generating this at: > > http://dscpl.user.openhosting.com/~grahamd/testing/form-html.txt > http://dscpl.user.openhosting.com/~grahamd/testing/details-html.txt > http://dscpl.user.openhosting.com/~grahamd/testing/details-py.txt > > I'll leave this up for a while, but will take it down at some point. > > Hope this helps. > > Graham > > Davin Boling wrote .. > >>(First of all, a big thanks to Graham for putting up with a thinly >>veiled attempt of escapism from Too Many Mailing Lists syndrome. :) That >>said, no offense to him, the e-mail he forwarded really wasn't mailing >>list material: I just wanted a quick second opinion to make sure I was >>sane.) >> >> >>I was working with my own custom handler when I ran into a random >>roadblock: for some reason the headers of submitted forms were being >>eaten, and I'm not using mod_python.publisher! With req.read() returning >>blank strings, it was obvious that util.FieldStorage(req) wasn't going >>to be of much use. I also tried a simple test, which offered some very >>bizarre results. I changed the top of my handler to the following: >> >>def handler(req): >> test = req.read() >> req.log_error(test) >> >>And this is what I get whenever I try to POST to it: >> >>[Wed Mar 16 19:27:53 2005] [error] [client X.X.X.X] GET, referer: >>http://real.url/nothere >> >>Very interesting, GET instead of POST. Maybe my HTML was at fault? I >>wrote up a small test form that was *nothing* but a good form: same result. >> >> >> >>At my wit's end, I wrote a quick handler from scratch and placed it into >>the same environment. I didn't restart Apache, all I did was make a copy >>of __init.py__ and overwrite it with a simple test. Interestingly >>enough, the "handler from scratch" worked as expected: req.read() >>returned a non-empty string, and req.method returned "POST". >> >>I overwrote __init.py__ again with the original version, and reran the >>same form. ...Back to GET again. It makes no sense! It's like something >>upstream is "eating" req.read(), but how is that possible when I'm >>fetching the contents of req.read *at the start* of my handler(req) >>function? >> >>Here's my Apache configuration for the virtual host in question, if it >>helps: >> >><VirtualHost 69.15.43.130:80> >>ServerName foo.bar.baz >>DocumentRoot /not/a/real/path >> <Directory /not/a/real/path> >> PythonDebug On >> SetHandler mod_python >> PythonHandler handler >> <IfModule mod_access.c> >> Order allow,deny >> Allow from all >> </IfModule> >> </Directory> >></VirtualHost> >> >> >> >>(I'd share the code in question, but it's going to be placed in a secure >>environment and I can't have it archived to the mailing list. I'll >>report my results when I find the culprit, but in the meantime I'd >>appreciate feedback on what people think might be going wrong.) >> >>_______________________________________________ >>Mod_python mailing list >>Mod_python at modpython.org >>http://mailman.modpython.org/mailman/listinfo/mod_python
|