使用 python 的 UTF-32 解码有问题
UTF-32 Decode using python is having issues
我在端口 80
上有一个 UDP python 服务器,我希望有人访问服务器并使用 UTF-32
发送编码消息 "Start Server" 但是当我试着解码它,它给出
request_code = bytes.decode(x, 'utf-32')
TypeError: descriptor 'decode' requires a 'bytes' object but received a 'tuple'
代码如下:
Constants.Server0 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Constants.Server0.bind((local_ip, udp_port_main))
Constants.Main_server_data = Constants.Server0.recvfrom(2048)
for x in Constants.Main_server_data:
request_code = bytes.decode(x, 'utf-32')
if request_code == 'Start Server':
print("Authorized!")
我需要这方面的帮助,可以帮我解决。
... The return value is a pair (string, address)
where string is a string representing the data received and address is the address of the socket sending the data.
所以尝试:
request_code = bytes.decode(x[0], 'utf-32')
或更好的风格:
for string, address in Constants.Main_server_data:
request_code = bytes.decode(string, 'utf-32')
我在端口 80
上有一个 UDP python 服务器,我希望有人访问服务器并使用 UTF-32
发送编码消息 "Start Server" 但是当我试着解码它,它给出
request_code = bytes.decode(x, 'utf-32')
TypeError: descriptor 'decode' requires a 'bytes' object but received a 'tuple'
代码如下:
Constants.Server0 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Constants.Server0.bind((local_ip, udp_port_main))
Constants.Main_server_data = Constants.Server0.recvfrom(2048)
for x in Constants.Main_server_data:
request_code = bytes.decode(x, 'utf-32')
if request_code == 'Start Server':
print("Authorized!")
我需要这方面的帮助,可以帮我解决。
... The return value is a pair
(string, address)
where string is a string representing the data received and address is the address of the socket sending the data.
所以尝试:
request_code = bytes.decode(x[0], 'utf-32')
或更好的风格:
for string, address in Constants.Main_server_data:
request_code = bytes.decode(string, 'utf-32')