I’ve got a JSON string that I’m posting to my Python script. This is an example string:
{"uid":"1111111","method":"check_user"}
In my Python code I simply call simplejson.loads( str ) where str is the JSON string from the request. The JSON string seems fine as when I print it at request time it’s intact. However I get a ValueError:
Extra data: line 1 column 41 - line 1 column 48 (char 41 - 48)
Traceback (most recent call last): File
"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/_webapp25.py",
line 703, in __call__
handler.post(*groups) File "/Users/.../app/controller/api_controller.py", line 25, in post
req = simplejson.loads( req ) File
"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_0_96/django/utils/simplejson/__init__.py",
line 232, in loads
return cls(encoding=encoding, **kw).decode(s) File
"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_0_96/django/utils/simplejson/decoder.py",
line 254, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
Any ideas what it may be? I’ve tried removing new lines, tabs and slashes from the string, even decoding it using .decode('string_escape')
You’ve got some unprintable character in your string. I get the same error if I append a null byte to the end of the string, and
printing it doesn’t show the problem:Print the
reprof your string at request time and you should see it.