HTTP Request With Data Problem

21 views
Skip to first unread message

Jay Poss

unread,
Jan 30, 2013, 4:18:48 PM1/30/13
to aspen...@googlegroups.com
This may be related to issue #129.

If no data is sent in the request, the simplate works fine.

If data is included, I get the following error:
  File "/home1/posscode/python/lib/python2.7/urlparse.py", line 387, in parse_qsl,
  ValueError: bad query field: '{"x":"87d7"}'

I am using jQuery $.ajax function.
The data attribute is set to the string as shown in the error msg.
I am using the default contentType which is: 'application/x-www-form-urlencoded; charset=UTF-8'

Neither POST or GET is working,
The simplate page does not appear to be invoked at all.

Any suggestions are appreciated.

Jay Poss

unread,
Jan 31, 2013, 10:16:23 AM1/31/13
to aspen...@googlegroups.com
Got it working.
I have a web page that sends json formatted data, via Ajax POST, to an Aspen web service.
The ajax.contentType  defaults to format that specifies the request data look like: fld1=val1&fld2=val2
JSON does not look like that, which was causing the Python parsing error.

I changed the ajax.contentType to 'application/json', which eliminated the error, but request.body is empty.

Solution:
import json
postData = json.loads(request.body.raw)

I don't know if the ajax content type matters, just so its not the default (application/x-www-form-urlencoded)
(suppose it is geared to work for a standard html form submit)
Reply all
Reply to author
Forward
0 new messages