-
Notifications
You must be signed in to change notification settings - Fork 85
Description
emonhub (specifically EmonHubMqttInterfacer.py) throws the following error when using Paho Client >=2.0
2025-06-07T20:44:34.517177+12:00 fnlctl systemd[1]: Started emonhub.service - emonHub data multiplexer.
2025-06-07T20:44:34.674514+12:00 fnlctl emonhub[10841]: Exception ignored in: <function Client.__del__ at 0x767855f963e0>
2025-06-07T20:44:34.682733+12:00 fnlctl emonhub[10841]: Traceback (most recent call last):
2025-06-07T20:44:34.682753+12:00 fnlctl emonhub[10841]: File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 874, in __del__
2025-06-07T20:44:34.682781+12:00 fnlctl emonhub[10841]: self._reset_sockets()
2025-06-07T20:44:34.682792+12:00 fnlctl emonhub[10841]: File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
2025-06-07T20:44:34.682811+12:00 fnlctl emonhub[10841]: self._sock_close()
2025-06-07T20:44:34.682824+12:00 fnlctl emonhub[10841]: File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1119, in _sock_close
2025-06-07T20:44:34.683032+12:00 fnlctl emonhub[10841]: if not self._sock:
2025-06-07T20:44:34.683409+12:00 fnlctl emonhub[10841]: AttributeError: 'Client' object has no attribute '_sock'
Emonhub verison: v2.7.2
Paho version: 2.0.0-1
Quick fix is to change the following line:
self._mqttc = mqtt.Client() |
to be self._mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
after which everthing works ok.
Alternatively you could look to change the on_connect and on-disconnect callbacks to replace the rc
with reason_code
See https://eclipse.dev/paho/files/paho.mqtt.python/html/migrations.html for details on the version changes, but this will also include changing the comparisons for values other than zero.
Note this will be a breaking change for those running <Paho 2.0, and either they would need to upgrade Paho to >=2.0 or if the 'quickfix' option was taken to add the legacy callback version, they could just revert that line to self._mqttc = mqtt.Client()