I've been trying a little AJAX with SACK:
http://www.twilightuniverse.com/projects/sack/
I'm getting a lot of 405 errors with CherryPy server.
The requests fail most of the time, succeed occasionally.
This shows on web.py 0.22 console on Windows:
127.0.0.1:1883 - - [26/Dec/2007 02:00:09] "HTTP/1.1 POST /req" - 200 OK
127.0.0.1:1883 - - [26/Dec/2007 02:00:11] "HTTP/1.1 rndval=1198663209684POST /req" - 405 Method Not Allowed
127.0.0.1:1883 - - [26/Dec/2007 02:00:11] "HTTP/1.1 rndval=1198663211026POST /req" - 405 Method Not Allowed
I then switched to runbasic, and most requests succeed. The failed
ones don't give an error code though. Just no result. The request
handler class is called but the result is not picked up by the
browser. Any ideas why it fails sometimes?
--
Best regards,
Jack
This log makes it look like the HTTP method being sent is
"rndval=<random integer>POST". Obviously, that isn't a valid HTTP
method. I can't imagine what kind of bug could result in this, but
maybe it's some kind of printed debug info that's making its way into
the HTTP request somehow?
--
Gary
http://blog.extracheese.org
Aah, I know what is happening.
When you send a POST request and not read the input, it gets available
to the next request.
For example consider the following 2 requests.
POST /path1 HTTP/1.1
k1: v1
k2: v2
rndval=1234
GET /path2 HTTP/1.1
k1: v1
k2:v2
Since the data in POST request is not read, the second request's
method becomes rndval=1234GET.
Even I noticed this once. This happens only with cherrypy webserver
and not with lighttpd or apache.
If you make sure you read all the given input data, it will be OK. You
may add the following unloadhook.
web.unloadhooks['input'] = web.input
How do I guarantee that I read all post data?
> web.unloadhooks['input'] = web.input
And what exactly does this do? Will this make sure all data is read
before the next request?
It should really be the web server's responsibility to understand
the HTTP protocol and parse the data though.
Thanks
Jack
It is there in 0.2x, but 0.3 will not have it.
> If you make sure you read all the given input data, it will be OK. You
> may add the following unloadhook.
> web.unloadhooks['input'] = web.input
Without understanding how it works, I put that line before
web.run(urls, globals(), web.reloader)
and my ajax calls seem to work fine with both CherryPy and
SimpleHTTPServer.
Thanks,
Jack
web.py runs all unloadhooks after handling every request. Since
web.input is added to unloadhooks, it will be called for every
request. This will make sure that all POST data is read and nothing is
left to interfere with the next request.