agilescientific / modelr-app

Modelr front end
Apache License 2.0
0 stars 1 forks source link

JSON when there is no reflection interface #159

Closed ben-bougher closed 9 years ago

ben-bougher commented 9 years ago

0 is not JSON serializable Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1536, in call rv = self.handle_exception(request, response, e) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1530, in call rv = self.router.dispatch(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1278, in default_dispatcher return route.handler_adapter(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1102, in call return handler.dispatch() File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 572, in dispatch return self.handle_exception(e, self.app.debug) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 570, in dispatch return method(_args, _kwargs) File "/base/data/home/apps/s~modelr-testing/1.385099113813051127/lib_auth.py", line 286, in authenticate_and_call return func(self, user,_args, _kwargs) File "/base/data/home/apps/s~modelr-testing/1.385099113813051127/web_api.py", line 715, in post self.response.write(json.dumps(output)) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/json/init.py", line 243, in dumps return _default_encoder.encode(obj) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/json/encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/json/encoder.py", line 270, in iterencode return _iterencode(o, 0) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/json/encoder.py", line 184, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: 0 is not JSON serializable

kwinkunks commented 9 years ago

This is like what I was getting with my freqbot code...

Horrible workaround is to cast to a string before json dumping.

It's weird, some lists are OK, but others (especially long ones or empty ones) seem to fail.

ben-bougher commented 9 years ago

I think this fixes it. http://stackoverflow.com/questions/11561932/why-does-json-dumpslistnp-arange5-fail-while-json-dumpsnp-arange5-tolis

kwinkunks commented 9 years ago

Awesome Ben, thanks for the tip! I was using list(a), not a.tolist()