2014-11-03 208 views
0

我有一台运行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

+0

你可以发布你的(或部分)脚本,以便我们可以看看吗? – hardillb 2014-11-03 22:46:07

+0

什么版本的蚊子?我敢打赌你在0.15或1.2.x. – ralight 2014-11-03 23:03:45

+0

@ralight我刚刚安装了蚊子版本1.3.5(build date 2014-10-08 22:31:34 + 0000),希望能够解决这个问题。但是,它没有。 – Daniel 2014-11-03 23:29:52

回答

0

此代码是否产生相同的问题?这可能等同于代码失败的地步。

import socket 

sock = socket.create_connection(("test.mosquitto.org", 1883)) 
+0

呃,好主意,我一回到办公室就会测试一下。 – Daniel 2014-11-05 22:41:45

相关问题