UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 10: ordinal not in range(128)

时间:2022-06-01 16:35:58

Python 2.7 执行时报错:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 10: ordinal not in range(128)

python2.7的默认编码是ascii,代码中包含了utf8字符。

修改系统的默认编码为utf8解决:

if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')