小编Sha*_*Ali的帖子

字节类型的UnicodeDecodeError

使用Python 3.4我尝试使用utf-32解码字节类型时出现以下错误

Traceback (most recent call last):
  File "c:.\SharqBot.py", line 1130, in <module>
    fullR=s.recv(1024).decode('utf-32').split('\r\n')
UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 0-3: codepoint not in range(0x110000)
Run Code Online (Sandbox Code Playgroud)

以及尝试将其解码为utf-16时的以下内容

  File "c:.\SharqBot.py", line 1128, in <module>
    fullR=s.recv(1024).decode('utf-16').split('\r\n')
UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x0a in position 374: truncated data
Run Code Online (Sandbox Code Playgroud)

当我使用utf-8解码时没有错误.s是连接到端口80上的抽搐IRC服务器irc.chat.twitch.tv的套接字.

它收到以下内容:

b':tmi.twitch.tv 001 absolutelyabot :Welcome, GLHF!\r\n:tmi.twitch.tv 002 absolutelyabot :Your host is tmi.twitch.tv\r\n:tmi.twitch.tv 003 absolutelyabot :This server is rather new\r\n:tmi.twitch.tv 004 absolutelyabot :-\r\n:tmi.twitch.tv 375 absolutelyabot :-\r\n:tmi.twitch.tv 372 absolutelyabot :You are in a maze …
Run Code Online (Sandbox Code Playgroud)

python decode utf-8 utf-16 python-3.x

4
推荐指数
2
解决办法
8949
查看次数

标签 统计

decode ×1

python ×1

python-3.x ×1

utf-16 ×1

utf-8 ×1