Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

aio.receive method creates 404 not found error
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

aio.receive method creates 404 not found error

by hwdornbush on Thu Jul 09, 2020 5:59 pm

I have created two python programs that successfully send temperature and humidity data to Adafruit IO
I created a new feed named digital, a new dashboard named digital, and a new block to toggle the LED on and off.
I tried the example program digital_out.py from https://learn.adafruit.com/adafruit-io- ... ython-code
I added my ADAFRUIT_IO_KEY and ADAFRUIT_IO_USERNAME
I made no other changes to this example code.

When I run it, I get:

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

I tried reloading adafruit-io:

$ pip3 install adafruit-io
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: adafruit-io in ./.local/lib/python3.7/site-packages (2.4.0)
Requirement already satisfied: paho-mqtt in ./.local/lib/python3.7/site-packages (from adafruit-io) (1.5.0)
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from adafruit-io) (2.21.0)

I looked through bug reports and saw two similar reports which requested

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
feeds = aio.feeds()
print(feeds)

be added to the script, so I did this. As a result, I get

[Feed(name='Welcome Feed', key='welcome-feed', description=None, unit_type=None, unit_symbol=None, history=True, visibility='private', license=None, status_notify=False, status_timeout=4320), Feed(name='temperature', key='temperature', description='temperature and humidity feed from Pi DHT22', unit_type=None, unit_symbol=None, history=True, visibility='private', license=None, status_notify=False, status_timeout=4320), Feed(name='humidity', key='humidity', description='', unit_type=None, unit_symbol=None, history=True, visibility='private', license=None, status_notify=False, status_timeout=4320), Feed(name='digital', key='digital', description=None, unit_type=None, unit_symbol=None, history=True, visibility='private', license=None, status_notify=False, status_timeout=4320)]

How do I get this example code to run successfully?

hwdornbush
 
Posts: 3
Joined: Tue Mar 21, 2017 5:30 pm

Re: aio.receive method creates 404 not found error

by brubell on Fri Jul 10, 2020 10:02 am

I'm unable to replicate the 404 error:

Code: Select all | TOGGLE FULL SIZE
# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed, RequestError

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

try: # if we have a 'digital' feed
    digital = aio.feeds('digital')
except RequestError: # create a digital feed
    feed = Feed(name="digital")
    digital = aio.create_feed(feed)



data = aio.receive(digital.key)
print(data)

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


Could you try running this code and letting me know if it also 404s?

brubell
 
Posts: 988
Joined: Fri Jul 17, 2015 10:33 pm

Re: aio.receive method creates 404 not found error

by brubell on Fri Jul 10, 2020 10:37 am

Edit - I was able to reproduce this with by making a new digital feed. The call to `receive` in Python calls our API's `digital/last.json` which throws a 404 no data exists (which is True on the first run). A quick workaround would be to write a 0 value to the feed by calling aio.send(digital.key, '0') before entering the while True loop.

I filed an issue over on the repository so we can better handle this exception without needing a workaround.

brubell
 
Posts: 988
Joined: Fri Jul 17, 2015 10:33 pm

Re: aio.receive method creates 404 not found error

by hwdornbush on Fri Jul 10, 2020 12:41 pm

Yes, I inserted your suggested code of

aio.send(digital.key, '0')

which got the code to go by the initial 404 error. However, the default choice of blocks includes one that provides ON or OFF, not 1 or 0. As a result, the example code fails when it receives ON rather than 1 from AIO.

I changed your suggested code to

aio.send(digital.key, 'OFF')

I now get the print output that the "received" value is either ON or OFF but the LED does not respond.

I changed the code for controlling the LED to

if data.value == 'ON':
led.value = True
else:
led.value = False

This works. I changed the block so that its values are 1 or 0 rather than On or Off, and now the original code works.

hwdornbush
 
Posts: 3
Joined: Tue Mar 21, 2017 5:30 pm

Please be positive and constructive with your questions and comments.