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

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

在 Plotly 教程中尝试绘制基本图表时出现错误:https://plot.ly/python/getting-started/

这里有完整的回溯:

回溯(最近调用最后):

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'

谢谢!

完全公开,我为 Plotly 工作。

TL;DR

最近的更改似乎与您的 Python 版本不完全兼容。

pip install -I 'plotly==1.6.10'

那是在影响您的更改之前。

说明

Plotly python 模块最近更新了我们的自定义 JSONEncoder 子类,将 float('NaN')float('Inf')float('-Inf') 转换为 null而不是扩展 JSON 值 nanInfinity-Infinity.

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

为此,我们从默认值 JSONEncoder 中覆盖了 iterencode。我们开发的这个版本和您的版本之间可能有所不同。

永久修复

我们将尝试重新创建错误并尽快提出修复,感谢您发布相关信息!

(编辑,pip 命令中应该有两个 = 符号)