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

来源:互联网 发布:iscroll.js 官网下载 编辑:程序博客网 时间:2024/05/16 10:38
混淆了 python2 里边的 str 和 unicode 数据类型。
0. 你需要的是让编码用实际编码而不是 ascii

1. 对需要 str->unicode 的代码,可以在出错的脚本前几行写上 :
import sys
reload(sys)

sys.setdefaultencoding('utf8')

把 str 编码由 ascii 改为 utf8 (或 gb18030) 即可解决问题。

2. python3 区分了 unicode str 和 byte arrary,并且默认编码不再是 ascii。
0 0
原创粉丝点击