Tobi S
Tobi S

Reputation: 161

python unable to connect to mqtt broker

When I was trying out a tutorial in the internet, I failed to connect to the mqtt broker - anyone can help me on that?

import paho.mqtt.client as mqtt

broker_url = "mqtt.eclipse.org"
broker_port = 1883
client = mqtt.Client()
client.connect(broker_url, broker_port)
print(client)
Traceback (most recent call last):  
  File "C:\Workspace\FI Systemintegration\Python\MitarbeiterVerwaltung\rpi\connect.py",   line 6, in <module>  
    client.connect(broker_url, broker_port)  
  File "C:\Users\TorbenIT\AppData\Local\Programs\Python\Python310\lib\site-packages  \paho\mqtt\client.py", line 914, in connect  
    return self.reconnect()  
  File "C:\Users\TorbenIT\AppData\Local\Programs\Python\Python310\lib\site-packages  \paho\mqtt\client.py", line 1044, in reconnect  
    sock = self._create_socket_connection()  
  File "C:\Users\TorbenIT\AppData\Local\Programs\Python\Python310\lib\site-packages  \paho\mqtt\client.py", line 3685, in _create_socket_connection  
    return socket.create_connection(addr, timeout=self._connect_timeout,   source_address=source)  
  File "C:\Users\TorbenIT\AppData\Local\Programs\Python\Python310\lib\socket.py", line   824, in create_connection  
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):  
  File "C:\Users\TorbenIT\AppData\Local\Programs\Python\Python310\lib\socket.py", line   955, in getaddrinfo  
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):  
socket.gaierror: [Errno 11001] getaddrinfo failed  

Upvotes: 1

Views: 1459

Answers (2)

Aril Spetalen
Aril Spetalen

Reputation: 31

I'm trying to follow a demo (this old one: http://www.steves-internet-guide.com/into-mqtt-python-client/), which suggests to use the same public broker. It doesn't work.

Moving from mqtt.eclipse.org to broker.hivemq.com works for me today.

Upvotes: 0

Lawrence Bird
Lawrence Bird

Reputation: 505

The service does not exist at mqtt.eclipse.org. It was either used only as an example or the service is no longer available.

You should use another MQTT instance, maybe run a local instance instead.

enter image description here

Upvotes: 1

Related Questions