String 将字符串转换为十六进制字符

String 将字符串转换为十六进制字符,string,python-2.7,hex,String,Python 2.7,Hex,我有以下短代码: 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\x0

我有以下短代码:

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")
结果如下:

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

收到的信息:☺00AB12☻02000D600004001♥t

我一直关注的是如何将“接收到的消息”从服务器解码回十六进制字符

谢谢 亚历克西斯请试试这个密码

import binascii
mytext='☺00AB12☻0200D60000040001♥t'
print binascii.hexlify(mytext)
我已经收到了这个输出

3f3030414231323f303230304436303030303034303030313f74