adafruit / Adafruit_IO_Python

Adafruit IO Python Client Library
Other
225 stars 99 forks source link

Receiving a feed with no data points raises 404 RequestError #119

Open brentru opened 4 years ago

brentru commented 4 years ago

Calling client.receive on a newly created feed with no data points raises a 404 if no data exists on the feed.

Update the library to not error on that call with a 404, and instead return a None value or a Data type which sets the value as None:

Data(created_epoch=None, created_at='2020-07-10T13:52:52Z', updated_at='2020-07-10T13:52:52Z', value='None', completed_at=None, feed_id=1157950, expiration='1599573172.0', position=None, id='0EG0X017NKRDS5527E3YXN0VP4', lat=None, lon=None, ele=None)

Example code

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
try: # i we have a 'digital' feed
    digital = aio.feeds('digital')
except RequestError: # create a digital feed
    feed = Feed(name="digital")
    digital = aio.create_feed(feed)
while True:
    print(digital)
    data = aio.receive(digital.key)
    time.sleep(0.5)

Output

Traceback (most recent call last):
File "/home/pi/Documents/digital_out.py", line 45, in <module>
data = aio.receive(digital.key)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 216, in receive
return Data.from_dict(self._get(path))
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 118, in _get
self._handle_error(response)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 108, in _handle_error
raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - API documentation can be found at https://io.adafruit.com/api/docs
blacklight commented 3 years ago

Not sure if this library is still maintained, but this is a core breaking bug that has been open for at least a year. Is there any plan to tackle it or will someone try and fork the library?

RobisLV commented 3 years ago

Can confirm. I am experiencing the same bug.

>>> aio.receive("myfeed") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.7/dist-packages/adafruit_io-2.5.0-py3.7.egg/Adafruit_IO/client.py", line 216, in receive File "/usr/local/lib/python3.7/dist-packages/adafruit_io-2.5.0-py3.7.egg/Adafruit_IO/client.py", line 118, in _get File "/usr/local/lib/python3.7/dist-packages/adafruit_io-2.5.0-py3.7.egg/Adafruit_IO/client.py", line 108, in _handle_error Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - API documentation can be found at https://io.adafruit.com/api/docs

brunofcat commented 2 years ago

the same issue.