python - Python3, json causes TypeError but simplejson doesn't -
i'm running latest python3 (with anaconda distribution) , have problem standard library installed json causes traceback:
traceback (most recent call last): file "c:\users\think\anaconda3\lib\site-packages\werkzeug\serving.py", line 193, in run_wsgi execute(self.server.app) file "c:\users\think\anaconda3\lib\site-packages\werkzeug\serving.py", line 181, in execute application_iter = app(environ, start_response) file "c:\users\think\my_server.py", line 148, in __call__ return self.wsgi_app(environ, start_response) file "c:\users\think\my_server.py", line 144, in wsgi_app response = self.dispatch_request(request) file "c:\users\think\my_server.py", line 80, in dispatch_request return getattr(self, 'on_' + endpoint)(request, **values) file "c:\users\think\my_server.py", line 54, in on_xapi_request json_data = self.load_json(request.data) file "c:\users\think\my_server.py", line 60, in load_json return json.loads(data) file "c:\users\think\anaconda3\lib\json\__init__.py", line 312, in loads s.__class__.__name__)) typeerror: json object must str, not 'bytes'
but, simplejson doesn't cause error.
use str.decode('utf-8')
before passing json.loads
i think line:
return json.loads(data)
is causing problem. decode data before passing function.
Comments
Post a Comment