(Python 2.6/3.0+)UnicodeDecodeError: 'ascii' codec can't decode

来源:互联网 发布:airplayer for mac 编辑:程序博客网 时间:2024/05/17 04:05
混淆了 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 

原创粉丝点击