将字符串转换为HEX字符

ale*_*xis 2 string hex python-2.7

我有以下简短代码:

import socket
from sys import *

host = "10.10.10.10"
port = 7142
buf  = 1024

tcpSock = socket.socket()
tcpSock.settimeout(100)
tcpSock.connect((host,port))

## Send message
data ='\x01\x30\x41\x30\x41\x30\x36\x02\x30\x31\x44\x36\x03\x74\x0d'
if(tcpSock.send(data)):    
    print "Sending message:",data
data = tcpSock.recv(4096) 
tcpSock.close()

print "Received message:", data
#print "Received message:", data.strip().decode("hex")
Run Code Online (Sandbox Code Playgroud)

输出是:

发送信息:☺0A0A06☻01D6♥t

收到留言:☺00AB12☻0200D60000040001♥t

我被困在哪里是如何解码从服务器回到HEX字符的"收到的消息"

谢谢亚历克西斯

Eug*_*ene 5

请试试这段代码

import binascii
mytext='?00AB12?0200D60000040001?t'
print binascii.hexlify(mytext)
Run Code Online (Sandbox Code Playgroud)

我收到了这个输出

3f3030414231323f303230304436303030303034303030313f74
Run Code Online (Sandbox Code Playgroud)