Description
Building a web app using flask
and the PlotlyJSONEncoder
doesn't work as soon as simplejson
is installed. Flask will automatically use simplejson
then (and doesn't provide the option to use the inbuilt one), with which PlotlyJSONEncoder
breaks simplejson
.
E.g. my flask code
if __name__ == "__main__":
app.json_encoder = plotly.utils.PlotlyJSONEncoder
app.run(threaded=True,
host="127.0.0.1",
port=int("5001")
)
works fine until simplejson
is installed, then it throws type errors:
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 1813, in wsgi_app
ctx.push()
File "C:\Anaconda3\lib\site-packages\flask\ctx.py", line 321, in push
self.session = self.app.open_session(self.request)
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 825, in open_session
return self.session_interface.open_session(self, request)
File "C:\Anaconda3\lib\site-packages\flask\sessions.py", line 302, in open_session
s = self.get_signing_serializer(app)
File "C:\Anaconda3\lib\site-packages\flask\sessions.py", line 299, in get_signing_serializer
signer_kwargs=signer_kwargs)
File "C:\Anaconda3\lib\site-packages\itsdangerous.py", line 519, in __init__
self.is_text_serializer = is_text_serializer(serializer)
File "C:\Anaconda3\lib\site-packages\itsdangerous.py", line 69, in is_text_serializer
return isinstance(serializer.dumps({}), text_type)
File "C:\Anaconda3\lib\site-packages\flask\sessions.py", line 85, in dumps
return json.dumps(_tag(value), separators=(',', ':'))
File "C:\Anaconda3\lib\site-packages\flask\json.py", line 128, in dumps
rv = _json.dumps(obj, **kwargs)
File "C:\Anaconda3\lib\site-packages\simplejson\__init__.py", line 406, in dumps
**kw).encode(obj)
TypeError: __init__() got an unexpected keyword argument 'tuple_as_array'
Where tuple_as_array
is just an example, if I delete this one it will throw the same with all other json keywords (use_decimal, allow_nan, etc... ).
Since simplejson is the de facto standard and it's pretty hard to make sure that a package is not installed, I would assume that the best way would be to adopt the Plotly encoder to work with simplejson as well.
The installed versions are up to date according to Anaconda.