Skip to content

UnicodeDecodeError #19

@CodeMan-P

Description

@CodeMan-P
# -*- coding: utf-8 -*-
from echarts import Echart, Legend, Bar, Axis
chart = Echart(u'GDP',u'This is a fake chart')
chart.use(Bar('China',[2, 3, 4, 5]))
chart.use(Legend(['GDP']))
chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan', 'Feb']))
chart.plot()

报错:

Traceback (most recent call last):
  File "C:\Program Files\Python36\echats.py", line 8, in <module>
    chart.plot()
  File "C:\Program Files\Python36\lib\site-packages\echarts\__init__.py", line 105, in plot
    fobj.write(self._html())
  File "C:\Program Files\Python36\lib\site-packages\echarts\__init__.py", line 95, in _html
    template = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 250: illegal multibyte sequence

按提示改了下:~Python36\lib\site-packages\echarts_init_.py -->

def _html(self):
        with open(os.path.join(os.path.dirname(__file__), u'plot.j2'),'rb') as f:
            template = f.read()
            return template.replace(bytes('{{ opt }}',encoding='utf-8'),bytes(json.dumps(self.json, indent=4),encoding='utf-8'))

然后正常运行;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions