adafruit / adafruit/Adafruit_IO_Python
Receiving a feed with no data points raises 404 RequestError
- Dominant language
- Python
- Stars
- 230
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
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
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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.