Thanks for your response.

Unfortunately that example isn't quite the same as how json is processed 
from the body in main.py. I.e. it's using cStringIO I think. 

I can put together an example that highlights this I guess.

On Friday, May 24, 2013 12:53:14 PM UTC+12, Jonathan Lundell wrote:
>
> On 23 May 2013, at 5:35 PM, Matt <mjwa...@gmail.com <javascript:>> wrote:
>
> Hi there,
>
> I'm using Version 2.4.6-stable+timestamp.2013.05.17.14.52.19, Running on 
> mac, Python 2.7.2, no external JSON library installed.
>
> Sending the following data via PUT, application/json; charset=UTF-8:
>
> {"id": 3}
>
> results in a JSON parser error occurring at main.py:
>
>     if is_json:
>         try:
>             logging.info('before') <--- my addition
>             json_vars = sj.load(body)
>             logging.info('after') <--- my addition
>             body.seek(0)
>         except Exception, e: <--- my addition
>             logging.exception(e) <--- my addition
>             # incoherent request bodies can still be parsed "ad-hoc"
>             json_vars = {}
>             pass
>         # update vars and get_vars with what was posted as json
>         request.get_vars.update(json_vars)
>         request.vars.update(json_vars)
>
> INFO     2013-05-24 00:07:21,100 main.py:337] before
> INFO     2013-05-24 00:07:21,100 main.py:338] <module 'json' from 
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py'>
> ERROR    2013-05-24 00:07:21,100 main.py:346] No JSON object could be 
> decoded
> Traceback (most recent call last):
>   File "/Projects/www/app/gluon/main.py", line 340, in parse_get_post_vars
>     json_vars = sj.load(body)
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py",
>  
> line 278, in load
>     **kw)
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py",
>  
> line 326, in loads
>     return _default_decoder.decode(s)
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
>  
> line 366, in decode
>     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
>  
> line 384, in raw_decode
>     raise ValueError("No JSON object could be decoded")
>
> Appears to be related to the id() function for some reason, as changing 
> the attribute name to anything other than "id" works fine. 
>
> Help on built-in function id in module __builtin__:
>
> id(...)
>
>     id(object) -> integer
>
>     Return the identity of an object.  This is guaranteed to be unique 
> among
>     simultaneously existing objects.  (Hint: it's the object's memory
>     address.)
>
> If I explicitly force it to use contrib.simplejson. i.e. change the top of 
> main.py
>
> try:
>     import simplejson as sj #external installed library
> except:
>     try:
>         import contrib.simplejson as sj #pure python library <--- Pasted.
>     except:
>         import contrib.simplejson as sj #pure python library
>
> I get the same result.
>
> Any ideas?
>
>
> FWIW, json.loads('{"id": 3}') works fine.
>
> I'd try logging body.read() before the json.load call, and see what json 
> is actually getting. You could follow that with body.seek(0) if you want, 
> but since it's going to crash anyway...
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to