I make a fresh installation and run the example code:
import paho.mqtt.client as mqtt
import ssl
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("$SYS/#")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.tls_set()
client.connect("mqtt.eclipseprojects.io", 8883, 60)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()
I have an error:
Traceback (most recent call last):
File "mqtt.py", line 19, in <module>
client.connect("mqtt.eclipseprojects.io", 8883, 60)
File "/usr/local/lib/python3.7/dist-packages/paho_mqtt-1.6.1-py3.7.egg/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/dist-packages/paho_mqtt-1.6.1-py3.7.egg/paho/mqtt/client.py", line 1045, in reconnect
on_pre_connect = self.on_pre_connect
File "/usr/local/lib/python3.7/dist-packages/paho_mqtt-1.6.1-py3.7.egg/paho/mqtt/client.py", line 1863, in on_pre_connect
return self._on_pre_connect
AttributeError: 'Client' object has no attribute '_on_pre_connect'
Please help me... I don't find solution....