I have a remote server running mosquitto. I can connect to this server and exchange messages using mosquitto_pub and mosquitto_sub. If i try the same using some python with paho.mqtt.client I get no connection. My script keeps running but the on_connection hook is never called.. The same scripts however work flawlessly with my local mosquitto server.
What could possibly be the reason for the connection problems? How can I get some more feedback on what's happening? Any suggestions?
EDIT: I added a minimal code example
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()
EDIT 2: While playing around, I noted that replacing "localhost" with "test.mosquitto.org" resulted in OSError: [Errno 101] Network is unreachable
although I have no problems connecting to it via mosquitto_sub