如何修复 Paho-MQTT result code 5
当你在 paho-mqtt 中看到结果代码 5 时,这表示未授权!通常这意味着你没有设置正确的用户名和密码。
使用以下命令设置用户名和密码
paho_auth_example.py
client.username_pw_set("myusername", "aeNg8aibai0oiloo7xiad1iaju1uch")如何使用用户名和密码连接的示例:
paho_connect_example.py
client = mqtt.Client("mqtt-test") # client ID "mqtt-test"
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set("myusername", "aeNg8aibai0oiloo7xiad1iaju1uch")
client.connect('127.0.0.1', 1883)
client.loop_forever() # 启动网络守护进程If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow