Passing a JSON to a Web2py-based server. What am I missing?

112 views
Skip to first unread message

Carl

unread,
Jun 10, 2013, 12:54:19 PM6/10/13
to web...@googlegroups.com
I am passing the string {'POST' : 'query POST'} to my Web2py server code.

Looking at gluon/main/py and tracing into sj.load(body) at line 225
leads to Python/Lib/json/decoder.py but eventually gets to errmsg(), line 36, with 
msg = Expecting proper name.
doc = [{'POST' : 'qwerty POST'}]
pos = 2
end = None

I bet the answer is obvious (!) but can you point it out?

Derek

unread,
Jun 10, 2013, 1:10:41 PM6/10/13
to web...@googlegroups.com
Post the whole traceback. 

Also, I just want to make the comment that what you put here is not valid json...
{'POST' : 'query POST'}

Single quotes aren't allowed.
Verify your json by going here:


Also, before using JSON you might want to read the spec.

Any reason why you are using JSON? In most cases it's very inefficient. I'd recommend CSV or YAML.

Niphlod

unread,
Jun 10, 2013, 3:15:31 PM6/10/13
to web...@googlegroups.com
uhm. web2py handles usual encoded forms in multipart/form-data and application/x-www-form-urlencoded without problems. Additionally recent releases parse automatically into request.vars all requests that POST a json body if they're handled with content-type : application/json.
Inspect your POSTs with something like firebug to spot the issue you're facing.

@david: Posting YAML isn't quite a standard, although preferred to CSV, that is the most horrible way to pass around values for forms. CSV is good for passing around table data, but is not supported by any browser "natively" (i.e. you must build your own CSV serialization)...YAML has the exact same issue, but CSV has a major limit... How do you pass two values with the same name as {id : [1, 2] } with CSV :-D ?

Carl Roach

unread,
Jun 10, 2013, 3:19:24 PM6/10/13
to web...@googlegroups.com
JSON isn't Python :)

Of course single quotes was the issue!

I've now got data from my Java GWT client app. I'm using JSON because JavaScript luvs JSON and GWT overlays makes handling such data very straightforward.

--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/2bdfZCeRJYU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Derek

unread,
Jun 10, 2013, 6:15:01 PM6/10/13
to web...@googlegroups.com
I've frankly never tried to pass two values with the same name, so I have no idea how I'd do it. I suppose I'd extend the CSV beyond the RFC 4180 by adding in subfields and a seperator of '^' as is commonly done.
Yes, building your own serialization is a task to be done. You'd have to do that anyway if you didn't use jQuery. de-serialization (aka parsing) on the other hand could be handled much the same way as json, import a library, deserialize.

Overall, the cost isn't any different than JSON. https://github.com/nodeca/js-yaml You could use a jscript based parser and serializer.

The main benefit with going from JSON to CSV is of course multiple rows.
Reply all
Reply to author
Forward
0 new messages