0
4

1 回答 1

1

您的数据字符串可能缺少一些不可打印的字符:

>>> s = 'EvðŸ’\x9d👸ðŸ\x8f»'  # \x9d and \x8f aren't printable.
>>> print(s)                    # This looks like your mojibake.
EvðŸ’👸ðŸ»
>>> s.encode('mbcs').decode('utf8')
'Ev'

请注意,Python 的mbcs编解码器对应于 Windows 默认的 ANSI 编解码器。只有当Windows-1252我正在运行的默认 ANSI 编解码器(美国和西欧本地化版本的 Windows)时,它才匹配“sloppy-windows1252”。

另一个选项是您的原始 UTF-8 数据使用.decode('cp1252',errors='ignore'). 如果是这种情况,则两个字节丢失并且字符串不可逆。

于 2020-12-15T22:28:38.137 回答