paho 2.x
Describe the bug
After upgrading to paho-mqtt version 2.x, I encountered the following error:
ValueError: Unsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details
While I understand from the error that a callback_api_version parameter is now required.
Suggested Fix
mqttc = mqtt.Client('{}-{:d}'.format(SCRIPTNAME, os.getpid()), clean_session=True, userdata=self.userdata, protocol=mqtt.MQTTv31, mqtt.CallbackAPIVersion.VERSION1)
in place of
mqttc = mqtt.Client('{}-{:d}'.format(SCRIPTNAME, os.getpid()), clean_session=True, userdata=self.userdata, protocol=mqtt.MQTTv31)
As described on https://eclipse.dev/paho/files/paho.mqtt.python/html/migrations.html
I have alerady noticed the issue too and have previously tried the same suggestionvas yours, which as far as I remember is not backwards compatible with the old paho, currently can't test it again.
Did you checked if your suggestion is working also with the previous paho?
No, I haven’t tested it — that’s actually why I didn’t submit a pull request yet 🙂
On my machine, I simply worked around it with:
pip install paho-mqtt==1.6.1
But I’ll do some proper testing for both versions and send a PR accordingly.
Thx, that would be good (unfortunately I can't access my developer environment at the moment), take your time. Use a Python venv to test different lib versions before you install old libs with pip.
Using mqtt.CallbackAPIVersion.VERSION1 is not backward compatible (paho-mqtt 2.x changes are breaking changes) so this solution should solve any issues with different paho-mqtt