如何处理UnicodeDecodeError

问题描述 投票:0回答:1
str1="khloé kardashian"
str1.encode("ascii")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128)

如何以完美的方式对其进行编码。我也尝试过:

unicode(query,errors='replace')
TypeError: decoding Unicode is not supported
python unicode python-unicode unicode-string
1个回答
0
投票

改用utf-8

str1="khloé kardashian"
str1.encode("utf-8")
© www.soinside.com 2019 - 2024. All rights reserved.