我不断收到此错误:exceptions.UnicodeDecodeError - 'ASCII' 编解码器不能解码字节
<type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)
args = ('ascii', '\xe2\x9d\xb6 Senn =)', 0, 1, 'ordinal not in range(128)')
encoding = 'ascii'
end = 1
message = ''
object = '\xe2\x9d\xb6 Senn =)'
reason = 'ordinal not in range(128)'
start = 0
使用此代码:
steamFriend = data['response']['players'][i]
n = steamUser(steamFriend['personaname'].encode("utf-8"), steamFriend['steamid'], steamFriend['avatarfull'], steamFriend['profileurl'], steamFriend['personastate'], False)
有些东西这里要注意:
steamFriend
是一个JSON对象- 我只有时会得到这个错误,因为beca使用
steamFriend['personaname']
包含一些奇怪的符号(例如❶),并且我不知道如何正确解析,因此我不会收到错误。
任何帮助,非常感谢。 另外,\xe2\x9d\xb6 Senn =)
应该代表❶ Senn =)
,如果有帮助。
在我的网页抓取曾经有过类似的错误。该解决方案首先将字符串解码为ascii,然后编码为utf-8。或者也许相反... – 2014-12-11 04:31:10