“utf8”编解码器无法解码位置6中的字节0xc4:意外的d结尾

2024-10-01 17:39:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python在raspberrypi2上编写代码。在

我试图通过蓝牙同时向两个设备发送多个订单,但它不起作用。在

根据错误消息,当我向第二台设备发送订单时,我无法解码响应。我已经试过用“UTF-8”编码,但也没用。。。在

以下是错误消息:

Traceback (most recent call last):
  File "/home/pi/Desktop/Bluetooth-master/Bluetooth-master/rfcommcli.py", line 60, in <module>
    StartBTClient()
  File "/home/pi/Desktop/Bluetooth-master/Bluetooth-master/rfcommcli.py", line 54, in StartBTClient
    print('reception 2 : ', rec2.decode())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 6: unexpected end of data

你能帮我吗。在

代码如下:

^{pr2}$

Tags: 代码inpy订单master消息home错误
1条回答
网友
1楼 · 发布于 2024-10-01 17:39:06

显然,设备2用UTF-8编码值的部分字节(而不是全部字节)进行响应。在

在尝试解码之前,您需要确保已接收并组合了消息的所有字节。这可能涉及多次调用.recv()。在

相关问题 更多 >

    热门问题