python UnicodeDecodeError:“utf8”编解码器无法解码位置0中的字节0xfc:无效的开始字节

2024-04-26 03:19:49 发布

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

只是处理一些套接字并接收标题中提到的错误。下面是代码和详细错误。我已经看过其他一些类似的帖子,但我还没有解决我的问题。感谢您的帮助,如果您能尽可能简单地将事情分解,我会更好地理解

在解码后尝试打印(pwd)时:p[]#括号是我能做的最接近正方形的东西

解码前尝试打印(pwd)时:

b'P\x01\x00\x00'
b'\xfcH\x83\xe4\xf0\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff]I\xb8cmd\x00\x00\x00\x00\x00APAPH\x89\xe2WWWM1\xc0j\rYAP\xe2\xfcf\xc7D$T\x01\x01H\x8dD$\x18\xc6\x00hH\x89\xe6VPAPAPAPI\xff\xc0API\xff\xc8M\x89\xc1L\x89\xc1A\xbay\xcc?\x86\xff\xd5H1\xd2H\xff\xca\x8b\x0eA\xba\x08\x87\x1d`\xff\xd5\xbb\xf0\xb5\xa2VA\xba\xa6\x95\xbd\x9d\xff\xd5H\x83\xc4(<\x06|\n\x80\xfb\xe0u\x05\xbbG\x13roj\x00YA\x89\xda\xff\xd5'

错误:

Traceback (most recent call last):
  File "C:\Users\13472\Desktop\folder\testh\testv5\testmod3Copy3.py", line 87, in <module>
    Login()
  File "C:\Users\13472\Desktop\folder\testh\testv5\testmod3Copy3.py", line 37, in Login
    pwd = pwd.decode("utf-8").strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 0: invalid start byte

代码段:

passwd = "Anything"

def Login():

    global s
    while True:
            string1=("Login: ")
            string1=string1.encode("utf-8")
            s.send(string1)
            pwd = s.recv(1024)
            pwd = pwd.decode("utf-8")


            if pwd.strip() == passwd:
                    break

            else:
                    continue

    string2=("You are connected! ")
    string2=string2.encode("utf-8")
    s.send(string2)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
Login()


Tags: 错误pwdloginsocketutfx00x01xff

热门问题