我正在尝试将utorrent
dht网络中的bytes
从string
转换为UnicodeDecodeError
,但出现ping_query = {
't': '0f',
'y': 'q',
'q': 'ping',
'a': {'id': client_id}}
ping_query = bencode.encode(ping_query)
host = socket.gethostbyname('router.utorrent.com')
port = 6881
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect((host, port))
s.send(ping_query)
r = s.recvfrom(1024)
response_data = bencode.decode(r[0])
print(response_data['ip'].decode('utf-8'))
错误
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xeb in position 0: invalid continuation byte
但是我收到错误response_data['ip']
b'\xeb\xff6isQ\xffJ\xec)\xcd\xba\xab\xf2\xfb'
的示例:r
有什么想法吗?
编辑:这是来自b'd2:ip6:\x80j\xe4\x01\xea\xdb1:rd2:id20:\xeb\xff6isQ\xffJ\xec)\xcd\xba\xab\xf2\xfb\xe3F|\xc2ge1:t2:xd1:y1:re'
:{{1}}