GET_WATER_READING: Exception’NameError=name ‘SensorNotReadyError’ is not defined’. Traceback: [<FrameSummary file /home/pi/weathercam/ds18b20.py, line 52 in get_water_reading>]
I’m not sure of the correct format of RAISE to use. Any suggestions
First, since this exception is not in the standard exceptions (see Built-in Exceptions — Python 3.10.2 documentation), you have to import it from the package it belongs to (maybe add it to the w1thermsensor import?).
Second, I think you want to raise the exception like this:
raise SystemNotReadyError("some kind of error text here?") # this line uses the exception, not the rough class!
from w1thermsensor import W1ThermSensor, Unit, SensorNotReadyError, ResetValueError
Here are the different combination of RAISE I’ve tried and their associated errors
raise w1thermsensor.SensorNotReadyError
GET_WATER_READING: Exception'NameError=name 'w1thermsensor' is not defined'. Traceback: [<FrameSummary file /home/pi/weathercam/ds18b20.py, line 63 in get_water_reading>]
raise W1ThermSensor.SensorNotReadyError
GET_WATER_READING: Exception'AttributeError=type object 'W1ThermSensor' has no attribute 'SensorNotReadyError''. Traceback: [<FrameSummary file /home/pi/weathercam/ds18b20.py, line 63 in get_water_reading>]
raise SensorNotReadyError
GET_WATER_READING: Exception'TypeError=__init__() missing 1 required positional argument: 'sensor''. Traceback: [<FrameSummary file /home/pi/weathercam/ds18b20.py, line 63 in get_water_reading>]
When I saw this error reply, which indicated I was missing a sensor arguement, I tried the following and it worked. The variable ‘water_sensor’ is the return from calling W1ThermSensor() to connect to the sensor.
Steve, I missed seeing this and the help() would have also point to the need for the sensor. To be honest, I find the output of the help() for an exception very confusing.
Not all documentation is written well. And yes, some exceptions are especially not well written
Also the help() system for Python is aimed at experienced users, it does tend to show a lot more detail than beginners are expecting. The secret here is to learn to ignore most of it!