Deron Meranda
deron.meranda at gmail.com
Thu Aug 10 16:22:35 EDT 2006
On 8/10/06, Nando Drabik <nandogringo at gmail.com> wrote: > I would like some help fixing the problem I am stuck in. To make this as > short and simple as possible, it has mostly to do with the > cgi.FieldStorage class. I have: > > 1) mod_python installed correctly on apache2 > 2) File test.py (resides under cgi-bin): > 3) HTML file that sends out XMLHttpRequest from js > > test.py =============================== > #!/usr/bin/env python > > import sys, re, cgi > ... > fields = cgi.FieldStorage() > req = fields.getvalue("myVar") ## THIS IS WHERE THE WHOLE THING CRAHSES Do you realize that you are NOT using mod_python here? What you have is a standard CGI script, not a mod_python handler, and are using the standard Python "cgi" module. On the surface realize when you type it on the Firefox URL bar, it results in a GET request with the parameters URL-encoded into the URL itself. But your XMLHttpRequest is doing a POST. However you are just sending the data "myVar=10". Normally posted data should have the content type multipart/form-data. Or you need to set the content-type header appropriately. The CGI FieldStorage can only handle multipart/form-data and application/x-www-form-urlencoded. If you're sending raw JSON formatted text, then you can't expect to use the FieldStorage classes. You need to read and decode the request body directly. -- Deron Meranda
|