4

解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: or...

 2 years ago
source link: https://wuzhuti.cn/python-decodeerror-ascii-codec-cant-decode
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)

import sys
reload(sys)
sys.setdefaultencoding('utf8')

混淆了 python2 里边的 str 和 unicode 数据类型。

1、你需要的是让编码用实际编码而不是 ascii

2、对需要 str->unicode 的代码,可以在前边写上以上代码,把 str 编码由 ascii 改为 utf8 (或 gb18030)、

3、python3 区分了 unicode str 和 byte arrary,并且默认编码不再是 ascii

参考:解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK