python中使用paho.mqtt时on_message中的msg.payload返回参数编码格式问题

问题

在python中使用paho.mqtt时on_message中的msg.payload返回参数为16进制混合ascii码的格式,想输出纯16进制的报文,麻烦帮忙看一下

import time
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    if rc == 0:
        print("连接成功")
        print("Connected with result code " + str(rc))
def on_message(client, userdata, msg):
    mm = str(msg.payload).split("'")
    missige = mm[1]
    nowTime = time.strftime("%Y-%m-%d %H:%M:%S")
    print(msg.topic + " " + str(msg.payload))
    print(nowTime + missige)
    # print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic") 
client = mqtt.Client(protocol=3)
client.username_pw_set("admin", "password")
client.on_connect = on_connect
client.on_message = on_message
client.connect(host="192.168.1.101", port = 1883, keepalive=60)  # 订阅频道
time.sleep(1)
# client.subscribe("public")
client.subscribe([("#", 0), ("test", 2)])
client.loop_forever()



运行结果及报错内容

img

import time
import paho.mqtt.client as mqtt
 
 
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    if rc == 0:
        print("连接成功")
        print("Connected with result code " + str(rc))
 
 
def on_message(client, userdata, msg):
    mm = str(msg.payload).split("'")
    missige = mm[1]
    nowTime = time.strftime("%Y-%m-%d %H:%M:%S")
    # 转16进制
    msg_16=msg.payload.hex()
    print(msg.topic + " " + str(msg_16))
    print(nowTime + missige)
    # print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
 
client = mqtt.Client(protocol=3)
client.username_pw_set("admin", "password")
client.on_connect = on_connect
client.on_message = on_message
client.connect(host="192.168.1.101", port=1883, keepalive=60)  # 订阅频道
time.sleep(1)
# # client.subscribe("public")
client.subscribe([("#", 0), ("test", 2 )])
client.loop_forever()
 
 
 
 


转16进制:
msg_16 = msg.payload.hex()