python问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position

转:https://blog.csdn.net/jewelsu/article/details/78683024

https://www.cnblogs.com/yhl-yh/p/6728567.html

'ascii' codec can't decode byte 0xe8 in position

经过搜索,发现应该是因为python2.x的默认编码是ascii,而代码中可能由utf-8的字符导致,解决方法是设置utf-8。
找到出错的文件,在import后增加下面几行

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

 

'ascii' codec can't encode characters in position 8-50: ordinal not in range(128)

#coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
 

你可能感兴趣的:(python问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position)