|
python3运行报错UnicodeEncodeError: 'ascii' codec can't encode character '
python3在ubunt下运行报错如下:
- pprint.pprint(lfw)
- File "/usr/lib/python3.5/pprint.py", line 53, in pprint
- printer.pprint(object)
- File "/usr/lib/python3.5/pprint.py", line 139, in pprint
- self._format(object, self._stream, 0, 0, {}, 0)
- File "/usr/lib/python3.5/pprint.py", line 167, in _format
- p(self, object, stream, indent, allowance, context, level + 1)
- File "/usr/lib/python3.5/pprint.py", line 189, in _pprint_dict
- context, level)
- File "/usr/lib/python3.5/pprint.py", line 346, in _format_dict_items
- context, level)
- File "/usr/lib/python3.5/pprint.py", line 167, in _format
- p(self, object, stream, indent, allowance, context, level + 1)
- File "/usr/lib/python3.5/pprint.py", line 282, in _pprint_str
- write(rep)
- UnicodeEncodeError: 'ascii' codec can't encode character '\u2013' in position 15: ordinal not in range(128)
复制代码 折腾很久, 在pycharm上正常运行, 在ubuntu里报错, 害我还傻傻考虑是json编码出问题,想着要怎么强.get或者json强制转成utf-8编码。 把json以utf-8写入再读出.....
后来换个角度思考才发现原来解决问题这么简单。
两条命令:
|
|