Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

micropython - Circuit Python MQTT Exception Block

I'm using the Adafruit Circuit Python MQTT library and am trying to catch the errors being generated.

   while True:
    try:
        # Poll the message queue
        mqtt_client.loop()
    except (ValueError, RuntimeError, MMQTTException) as e:
        print("Failed to get data, retrying
", e)
      
        mqtt_client.reconnect()
        # continue
    time.sleep(1)

But this generates the following error:

NameError: name 'MMQTTException' is not defined

Any ideas how I should properly catch this error?

The library has the following error class. I'm guessing it needs to be exposed somehow?

class MMQTTException(Exception):
    """MiniMQTT Exception class."""

    # pylint: disable=unnecessary-pass
    # pass
question from:https://stackoverflow.com/questions/65947111/circuit-python-mqtt-exception-block

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you did something like

import adafruit_minimqtt.adafruit_minimqtt as MQTT

in order to be able to use mqtt_client = MQTT.MQTT(...), then you need to refer to this other class similarly, as MQTT.MMQTTException.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...