Tras una actualización de pip, el script del enfriador en nuestra Pi falla con el error "Unsupported callback API version"
Traducido del English por IA ·
No soy programador, dirijo una planta de alimentos. Nuestro técnico de mantenimiento, que ya no está con nosotros, escribió un script de Python en una Pi 3 que lee la temperatura del blast chiller y la envía a Hermetry. Llevaba dos años funcionando sin problemas. La semana pasada alguien ejecutó actualizaciones en la Pi (apt upgrade y un pip install –upgrade, según me dijeron) y ahora el servicio no arranca. journalctl muestra:
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
El enfriador tiene una regla de alarma en Hermetry, y ahora mismo nadie recibiría aviso si se calienta. Me gustaría que esto vuelva a funcionar hoy. ¿Qué tengo que cambiar?
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?
Traducido del English por IA ·
¿Qué versión de paho está instalada ahora? pip show paho-mqtt
Which paho version is on there now? pip show paho-mqtt
Traducido del English por IA ·
2.1.0. Las notas del técnico dicen 1.6.1.
2.1.0. The tech’s notes say 1.6.1.
Traducido del English por IA ·
La forma más rápida de volver atrás: ejecutar pip install paho-mqtt==1.6.1 y reiniciar el servicio. Después, solucionadlo de forma definitiva cuando tengáis tiempo.
Quickest way back: pip install paho-mqtt==1.6.1 and restart the service. Then fix it properly when there’s time.
Traducido del English por IA ·
Fijar la versión permite recuperar la alarma hoy. La solución adecuada son dos líneas. paho 2.x espera la versión de la API de callbacks como primer argumento, y su script pasa ahí el id del cliente, así que «chiller-pi» se interpreta como una versión de API. Cambie el constructor y la firma de 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)
No cambie el protocolo a MQTT 5 mientras esté en ello. Hermetry usa 3.1.1 y rechaza un CONNECT de MQTT 5 con el código de retorno 1. paho sigue usando 3.1.1 por defecto, así que dejarlo como está es lo correcto.Si el técnico tenía otros callbacks (on_disconnect, on_publish), también cambiaron de firma en 2.x; revise las notas de migración de cada uno.
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.
Traducido del English por IA ·
Cambié la línea; on_connect tenía los cuatro argumentos antiguos, así que también había que corregirlo. El servicio está activo, las lecturas vuelven a llegar a la placa y probé la alarma abriendo la puerta del chiller durante unos minutos. Gracias Aoife, y Ciarán por la solución provisional.
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.
Traducido del English por IA ·
Conviene anotar las versiones en un requirements.txt junto al script para que la próxima actualización no sorprenda a nadie.
Worth putting the versions in a requirements.txt next to the script so the next upgrade doesn’t surprise anyone.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

