Python Plotly: AttributeError: 'PlotlyJSONEncoder' object has no attribute 'encoding'

限于喜欢 提交于 2019-12-13 08:44:41

问题


I am getting an error when trying to plot the basic chart on the Plotly Tutorial: https://plot.ly/python/getting-started/.

Full traceback here:

Traceback (most recent call last):

File "testing_plotly.py", line 13, in unique_url = py.plot(data, filename = 'basic-line')

File "C:\Python34\lib\site-packages\plotly\plotly\plotly.py", line 186, in plot res = _send_to_plotly(figure, **plot_options)

File "C:\Python34\lib\site-packages\plotly\plotly\plotly.py", line 1229, in _se cls=utils.PlotlyJSONEncoder)

File "C:\Python34\lib\json__init__.py", line 237, in dumps **kw).encode(obj)

File "C:\Python34\lib\json\encoder.py", line 192, in encode chunks = self.iterencode(o, _one_shot=True)

File "C:\Python34\lib\site-packages\plotly\utils.py", line 151, in iterencode if self.encoding != 'utf-8': AttributeError: 'PlotlyJSONEncoder' object has no attribute 'encoding'

Thanks!


回答1:


Full disclosure, I work for Plotly.

TL;DR

Looks like a recent change isn't fully compatible with your Python version.

pip install -I 'plotly==1.6.10'

That's just before the change that seems to be affecting you.

Explanation

The Plotly python module recently just updated our custom JSONEncoder subclass to convert float('NaN'), float('Inf'), and float('-Inf') to null instead to to the extended JSON values nan, Infinity, and -Infinity.

https://docs.python.org/2/library/json.html#infinite-and-nan-number-values

To do this we overrode iterencode from the default JSONEncoder. Something may have changed between the version of this we develop on and your version.

Permanent Fix

We'll try and recreate the error and come up with a fix shortly, thanks for posting about it!

(edit, there should have been two = signs in the pip command)



来源:https://stackoverflow.com/questions/29022989/python-plotly-attributeerror-plotlyjsonencoder-object-has-no-attribute-enco

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!