0
何我会正确编码以下/解码错误:编码使用UTF-8
# # -*- coding: utf-8 -*-
>>> 'What\x80\x99s Up: Balloon to the Rescue!'.encode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 4: ordinal not in range(128)
>>> 'What\x80\x99s Up: Balloon to the Rescue!'.decode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 4: invalid start byte
你刚刚猜测OP意味着哪个字符? – beerbajay 2012-02-27 20:28:29
@beerbajay是的。鉴于两个字节是相同的,并且在上下文中非常合理,我想我可能是对的。 ;) – spencercw 2012-02-27 20:29:57
@spencercw是的,这似乎是一个上游问题。这是我在数据库中的价值,所以我认为在此之前我需要编码为utf。 – David542 2012-02-27 20:58:06