`
dacoolbaby
  • 浏览: 1255630 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

[转]解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5

 
阅读更多

通过搜集网上的资料,自己多次尝试,问题算是解决了,在代码中加上如下几句即可。

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

http://docs.python.org/howto/unicode.html 这个是python的unicode编码API文档,英文好的同学可以看一下,加深理解。

参考资料:http://groups.google.com/group/python-cn/browse_thread/thread/f48ef745452740f6?pli=1

点击打开链接

------------------------------------------------------------------------------------------------------------------------

 

混淆了 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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics