【发布时间】:2017-12-24 20:25:21
【问题描述】:
今天我的脚本中出现了奇怪的错误:
'utf8' codec can't decode byte 0xc3 in position 21: invalid continuation byte
我正在从套接字sock.recv 读取数据,结果是buff.decode('utf-8'),其中 buff 是返回的数据。
但是今天我发现了很多“独角兽”,其中一个字符返回“▒”
【问题讨论】:
今天我的脚本中出现了奇怪的错误:
'utf8' codec can't decode byte 0xc3 in position 21: invalid continuation byte
我正在从套接字sock.recv 读取数据,结果是buff.decode('utf-8'),其中 buff 是返回的数据。
但是今天我发现了很多“独角兽”,其中一个字符返回“▒”
【问题讨论】:
.decode() 的第二个参数名为 errors。您可以将其设置为 'ignore' 以忽略所有非 utf8 字符,或将其设置为 'replace' 以将它们替换为菱形问号 (�)。
buff.decode('utf-8', 'ignore')
【讨论】: