rpdswtk / mqtt_recorder

Simple cli tool for recording and replaying MQTT messages.
https://pypi.org/project/mqtt-recorder/
MIT License
22 stars 10 forks source link

'Client' object has no attribute '_sock' and missing 1 required positional argument: 'callback_api_version' #8

Open antun opened 5 months ago

antun commented 5 months ago

I just installed mqtt-recorder by running pip install mqtt-recorder. The output was:

Collecting mqtt-recorder
  Downloading mqtt_recorder-1.3.0-py3-none-any.whl.metadata (4.1 kB)
Collecting paho-mqtt>=1.6.1 (from mqtt-recorder)
  Downloading paho_mqtt-2.0.0-py3-none-any.whl.metadata (23 kB)
Requirement already satisfied: tqdm>=4.65.0 in /usr/local/var/pyenv/versions/3.9.18/lib/python3.9/site-packages (from mqtt-recorder) (4.66.2)
Downloading mqtt_recorder-1.3.0-py3-none-any.whl (6.5 kB)
Downloading paho_mqtt-2.0.0-py3-none-any.whl (66 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.9/66.9 kB 702.8 kB/s eta 0:00:00
Installing collected packages: paho-mqtt, mqtt-recorder
Successfully installed mqtt-recorder-1.3.0 paho-mqtt-2.0.0

When I try to record, I get an exception:

$ mqtt-recorder --host 192.168.65.122 --mode record --file recording.csv
Exception ignored in: <function Client.__del__ at 0x10e7c7ee0>
Traceback (most recent call last):
  File "/usr/local/var/pyenv/versions/3.9.18/lib/python3.9/site-packages/paho/mqtt/client.py", line 874, in __del__
    self._reset_sockets()
  File "/usr/local/var/pyenv/versions/3.9.18/lib/python3.9/site-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
    self._sock_close()
  File "/usr/local/var/pyenv/versions/3.9.18/lib/python3.9/site-packages/paho/mqtt/client.py", line 1119, in _sock_close
    if not self._sock:
AttributeError: 'Client' object has no attribute '_sock'
Traceback (most recent call last):
  File "/usr/local/var/pyenv/versions/3.9.18/bin/mqtt-recorder", line 8, in <module>
    sys.exit(main())
  File "/usr/local/var/pyenv/versions/3.9.18/lib/python3.9/site-packages/mqtt_recorder/__main__.py", line 144, in main
    recorder = MqttRecorder(
  File "/usr/local/var/pyenv/versions/3.9.18/lib/python3.9/site-packages/mqtt_recorder/recorder.py", line 34, in __init__
    self.__client = mqtt.Client(client_id=client_id)
TypeError: __init__() missing 1 required positional argument: 'callback_api_version'

It looks like these are related to the paho-mqtt client that mqtt-recorder uses, but I'm not sure what to do with those errors.

antun commented 5 months ago

I was able to get past this error by running pip install 'paho-mqtt<2.0.0' to install an older version of paho-mqtt, based on [this thread](pip install 'paho-mqtt<2.0.0'). Not sure if it's working correctly though.

hihiuztrewq commented 3 months ago

I got the same error.

I fixed it by changing line 34 in recorder.py from self.__client = mqtt.Client(client_id=client_id) to self.__client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, client_id=client_id)

(See: https://eclipse.dev/paho/files/paho.mqtt.python/html/migrations.html )