我有一臺運行mosquitto的遠程服務器。我可以連接到這個服務器並使用mosquitto_pub和mosquitto_sub交換消息。如果我嘗試使用paho.mqtt.client使用一些python,我沒有任何連接。我的腳本一直運行,但on_connection掛鉤永遠不會被調用。然而,相同的腳本完美地與我的本地mosquitto服務器一起工作。儘管mosquitto_pub工作正常,但無法使用paho.mqtt.client連接到Mosquitto服務器
什麼可能是連接問題的原因?我如何才能對發生的事情有更多的反饋?有什麼建議麼?
編輯:我添加了一個最小的代碼示例
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Yeeha")
client.subscribe("botgrid/init", qos=2)
def on_message(client, userdata, msg):
print(msg.payload)
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost")
print("Waiting for connection...")
client.loop_forever()
編輯2:在播放的時候,我注意到,「test.mosquitto.org」代替「localhost」的導致OSError: [Errno 101] Network is unreachable
我雖然連接沒有問題它通過mosquitto_sub
你可以發佈你的(或部分)腳本,以便我們可以看看嗎? – hardillb 2014-11-03 22:46:07
什麼版本的蚊子?我敢打賭你在0.15或1.2.x. – ralight 2014-11-03 23:03:45
@ralight我剛剛安裝了蚊子版本1.3.5(build date 2014-10-08 22:31:34 + 0000),希望能夠解決這個問題。但是,它沒有。 – Daniel 2014-11-03 23:29:52