Nach einem pip-Upgrade stürzt das Chiller-Skript auf unserem Pi mit dem Fehler "Unsupported callback API version" ab
Von English mit KI übersetzt ·
Ich bin kein Programmierer, ich betreibe eine Lebensmittelfabrik. Unser Wartungstechniker, der inzwischen gegangen ist, hat auf einem Pi 3 ein Python-Skript geschrieben, das die Temperatur des Blast Chillers liest und an Hermetry sendet. Zwei Jahre lang lief es problemlos. Letzte Woche hat jemand Updates auf dem Pi ausgeführt (apt upgrade und ein pip install –upgrade, wie mir gesagt wurde), und jetzt startet der Dienst nicht mehr. journalctl zeigt:
Traceback (most recent call last):
File "/home/pi/chiller/send.py", line 14, in <module>
client = mqtt.Client("chiller-pi")
File ".../paho/mqtt/client.py", line 772, in __init__
raise ValueError(
ValueError: Unsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details
In Hermetry gibt es eine Alarmregel für den Chiller, aber im Moment würde niemand benachrichtigt, wenn er sich erwärmt. Ich möchte, dass das heute wieder funktioniert. Was muss ich ändern?
Not a programmer, I run a food plant. Our maintenance tech, who has since left, wrote a Python script on a Pi 3 that reads the blast chiller temperature and sends it to Hermetry. It’s been fine for two years. Last week someone ran updates on the Pi (apt upgrade and a pip install –upgrade, I’m told) and now the service won’t start. journalctl shows:
Traceback (most recent call last):
File "/home/pi/chiller/send.py", line 14, in <module>
client = mqtt.Client("chiller-pi")
File ".../paho/mqtt/client.py", line 772, in __init__
raise ValueError(
ValueError: Unsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details
The chiller has an alarm rule in Hermetry and right now nobody would get told if it warms up, so I’d like this back today. What do I change?
Von English mit KI übersetzt ·
Welche paho-Version ist dort jetzt installiert? pip show paho-mqtt
Which paho version is on there now? pip show paho-mqtt
Von English mit KI übersetzt ·
2.1.0. In den Notizen des Technikers steht 1.6.1.
2.1.0. The tech’s notes say 1.6.1.
Von English mit KI übersetzt ·
Der schnellste Weg zurück: pip install paho-mqtt==1.6.1 ausführen und den Dienst neu starten. Die eigentliche Ursache sollten Sie dann bei Gelegenheit richtig beheben.
Quickest way back: pip install paho-mqtt==1.6.1 and restart the service. Then fix it properly when there’s time.
Von English mit KI übersetzt ·
Das Pinnen bringt den Alarm für heute wieder zum Laufen. Die richtige Lösung sind zwei Zeilen. paho 2.x erwartet die Callback-API-Version als erstes Argument, und Ihr Skript übergibt dort die Client-ID, daher wird „chiller-pi“ als API-Version interpretiert. Ändern Sie den Konstruktor und die Signatur von on_connect:
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, reason_code, properties):
print("connected:", reason_code)
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="chiller-pi")
client.on_connect = on_connect
client.username_pw_set("<ACCESS_TOKEN>") # token as username, empty password
client.tls_set()
client.connect("<device host>", 8883, keepalive=60)
client.loop_start()
...
client.publish("v1/telemetry", json.dumps({"chiller_temp_c": t}), qos=1)
Stellen Sie das Protokoll dabei nicht auf MQTT 5 um. Hermetry spricht 3.1.1 und lehnt ein MQTT-5-CONNECT mit Return-Code 1 ab. paho verwendet standardmäßig weiterhin 3.1.1, daher ist es richtig, es so zu belassen.Falls der Techniker weitere Callbacks (on_disconnect, on_publish) verwendet hat, haben sich deren Signaturen in 2.x ebenfalls geändert. Prüfen Sie die Migrationshinweise für jeden einzelnen.
Pinning works to get the alarm back today. The proper fix is two lines. paho 2.x wants the callback API version as the first argument, and your script passes the client id there, so „chiller-pi“ gets read as an API version. Change the constructor and the on_connect signature:
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, reason_code, properties):
print("connected:", reason_code)
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="chiller-pi")
client.on_connect = on_connect
client.username_pw_set("<ACCESS_TOKEN>") # token as username, empty password
client.tls_set()
client.connect("<device host>", 8883, keepalive=60)
client.loop_start()
...
client.publish("v1/telemetry", json.dumps({"chiller_temp_c": t}), qos=1)
Don’t switch the protocol to MQTT 5 while you’re in there. Hermetry speaks 3.1.1 and refuses an MQTT 5 CONNECT with return code 1. paho still defaults to 3.1.1, so leaving it alone is right.
If the tech had other callbacks (on_disconnect, on_publish), they changed signature in 2.x as well, check the migration notes for each one.
Von English mit KI übersetzt ·
Die Zeile geändert, bei on_connect standen noch die alten vier Argumente, also musste das auch angepasst werden. Der Dienst läuft, die Messwerte kommen wieder am Board an, und ich habe den Alarm getestet, indem ich die Chiller-Tür für ein paar Minuten geöffnet habe. Danke Aoife und Ciarán für die Zwischenlösung.
Changed the line, the on_connect had the old four arguments so that needed fixing too. Service is up, readings back on the board and I tested the alarm by opening the chiller door for a few minutes. Thanks Aoife, and Ciarán for the stopgap.
Von English mit KI übersetzt ·
Es lohnt sich, die Versionen in einer requirements.txt neben dem Skript abzulegen, damit das nächste Upgrade niemanden überrascht.
Worth putting the versions in a requirements.txt next to the script so the next upgrade doesn’t surprise anyone.
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.
Mitdiskutieren
Melde dich an, um Fragen zu stellen und zu beantworten, hilfreiche Beiträge mit „Gefällt mir“ zu markieren und die Antwort zu kennzeichnen, die dein Problem gelöst hat. Jeder Beitrag bringt Punkte und Stufen.

