码迷,mamicode.com
首页 > 编程语言 > 详细

python 编码问题解决方案

时间:2016-06-06 13:39:09      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

1.‘ascii‘ codec can‘t encode characters in position 6-7: ordinal not in range(128)

此问题原因是基本上是ascii编码方式,由此Python自然调用ascii编码解码程序去处理字符流,当字符流不属于ascii范围内,就会抛出异常(ordinal not in range(128))。

参考:http://wangye.org/blog/archives/629/

解决方案:

import sys
reload(sys)
sys.setdefaultencoding(
‘utf-8‘)

 

2.‘latin-1‘ codec can‘t encode characters in position 6-7: ordinal not in range(256)

参考:http://blog.csdn.net/u014744494/article/details/41986647

解决方案:

在下图所示处加上下面箭头所指那句,即图后蓝色代码

技术分享

account = accountraw.encode("utf-8").decode("latin1")

 

python 编码问题解决方案

标签:

原文地址:http://www.cnblogs.com/miranda-tang/p/5563322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!