Skip to content

Instantly share code, notes, and snippets.

@hockeybuggy
Created October 9, 2014 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hockeybuggy/de448e7ccb720a51b005 to your computer and use it in GitHub Desktop.
Save hockeybuggy/de448e7ccb720a51b005 to your computer and use it in GitHub Desktop.
Testing Flasks Jsonify method's behavior with lists and arrays
Traceback (most recent call last):
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/douglas/devel/random/jsonify_test/server.py", line 16, in array
return jsonify(a_array)
File "/home/douglas/devel/envs/forkchess/lib/python2.7/site-packages/flask/json.py", line 237, in jsonify
return current_app.response_class(dumps(dict(*args, **kwargs),
TypeError: cannot convert dictionary update sequence element #0 to a sequence
#!/usr/bin/env python
from flask import Flask
from flask import jsonify
app = Flask(__name__)
#app.secret_key="This is the super secret key... SHHHH"
app.debug = True
a_array = [1,2,3,4,5]
a_list = a_array
a_dict = {"array": a_array}
@app.route("/array")
def array():
return jsonify(a_array)
@app.route("/list")
def list():
return jsonify(a_list)
@app.route("/dict")
def dict():
return jsonify(a_dict)
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment