adafruit / Adafruit_IO_Python

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

create_feed method in Client causes 404 #102

Closed octubot closed 5 years ago

octubot commented 5 years ago

hello everybody, I am trying to use adafruit digital output example. I did everything as it was explained. However, I did modify the code so it could in my BBB.

this is the code i used. :

""" 'digital_out.py'

Example of turning on and off a LED from the Adafruit IO Python Client

Author(s): Brent Rubell, Todd Treece """

Import standard python modules

import time

import Adafruit_BBIO.GPIO as GPIO

import Adafruit IO REST client.

from Adafruit_IO import Client, Feed, RequestError

Set to your Adafruit IO key.

Remember, your key is a secret,

so make sure not to publish it when you publish this code!

ADAFRUIT_IO_KEY = 'XXXXXXXXXXXX'

Set to your Adafruit IO username.

(go to https://accounts.adafruit.com to find your username)

ADAFRUIT_IO_USERNAME = 'XXXXXXXXXX'

Create an instance of the REST client.

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

GPIO.setup("GPIO0_20", GPIO.OUT)

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)

led set up

while True: data = aio.receive(digital.key) if int(data.value) == 1: GPIO.output("GPIO0_20", GPIO.HIGH) print('received <- ON\n')

elif int(data.value) == 0:
    print('received <- OFF\n')
    GPIO.output("GPIO0_20", GPIO.LOW)

# timeout so we dont flood adafruit-io with requests
time.sleep(0.5)

However, I keep getting this error:

Traceback (most recent call last): File "aio1.py", line 38, in data = aio.receive(digital.key) File "/home/debian/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 216, in receive return Data.from_dict(self._get(path)) File "/home/debian/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 118, in _get self._handle_error(response) File "/home/debian/.local/lib/python3.5/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

please advise.

thank you.

brentru commented 5 years ago

@octubot How did you install this (pip or via setup)?

Do you see a digital feed listed on your Adafruit IO Feed page? -> https://io.adafruit.com/feeds

octubot commented 5 years ago

@octubot How did you install this (pip or via setup)?

Do you see a digital feed listed on your Adafruit IO Feed page? -> https://io.adafruit.com/feeds

yes I do see the feed

brentru commented 5 years ago

@octubot Could you attempt to make the client list your feeds by adding the following to your code?

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
feeds = aio.feeds()
print(feeds)
octubot commented 5 years ago

@octubot Could you attempt to make the client list your feeds by adding the following to your code?

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

i added this to my code and this was the results

[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='openiotdoor', key='openiotdoor', description=None, unit_type=None, unit_symbol=None, history=True, visibility='private', license=None, status_notify=False, status_timeout=4320), Feed(name='doors', key='doors', description=None, unit_type=None, unit_symbol=None, history=True, visibility='private', license=None, status_notify=False, status_timeout=4320), Feed(name='iotdoor', key='iotdoor', description=None, 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)] Traceback (most recent call last): File "/Users/zeyad/PycharmProjects/untitled/dwsd.py", line 42, in data = aio.receive(digital) File "/Users/zeyad/PycharmProjects/one/venv/lib/python3.7/site-packages/Adafruit_IO/client.py", line 216, in receive return Data.from_dict(self._get(path)) File "/Users/zeyad/PycharmProjects/one/venv/lib/python3.7/site-packages/Adafruit_IO/client.py", line 118, in _get self._handle_error(response) File "/Users/zeyad/PycharmProjects/one/venv/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 - that is an invalid URL, please check the API documentation at https://io.adafruit.com/api/docs to make sure your URL is correct

brentru commented 5 years ago

@octubot I was able to reproduce this on my end, it seems like the create_feed method isn't working.

I'll look into it, renaming the issue's topic to reflect the bug.

      4     test_feed = Feed(name='doesntexist')
----> 5     test_feed = aio.create_feed(test)
octubot commented 5 years ago

the code creates the feeds but if crashes idk why.

octubot commented 5 years ago

i tried this code to test the connection

""" 'digital_out.py'

Example of turning on and off a LED from the Adafruit IO Python Client

Author(s): Brent Rubell, Todd Treece """

Import standard python modules

import time

import Adafruit_BBIO.GPIO as GPIO

from Adafruit_IO import Client, Feed, RequestError

Set to your Adafruit IO key.

Remember, your key is a secret,

so make sure not to publish it when you publish this code!

ADAFRUIT_IO_KEY = 'XXXXXX'

Set to your Adafruit IO username.

(go to https://accounts.adafruit.com to find your username)

ADAFRUIT_IO_USERNAME = 'xxxxxx'

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')
feeds = aio.feeds()
print(feeds)

except RequestError: # create a digital feed feed = Feed(name="digital") digital = aio.create_feed(feed)'''

digital = aio.feeds('digital')

GPIO.setup("P8_8", GPIO.OUT)

while True: data = aio.receive(digital) if int(data.value) == 1: print('received <- ON\n')

GPIO.output("P8_8", GPIO.HIGH)

elif int(data.value) == 0:
    print('received <- OFF\n')
    #GPIO.output("P8_8", GPIO.LOW)

# timeout so we dont flood adafruit-io with requests
time.sleep(0.5)

the results were

Traceback (most recent call last): File "/Users/zeyad/PycharmProjects/untitled/dwsd.py", line 43, in data = aio.receive(digital) File "/Users/zeyad/PycharmProjects/one/venv/lib/python3.7/site-packages/Adafruit_IO/client.py", line 216, in receive return Data.from_dict(self._get(path)) File "/Users/zeyad/PycharmProjects/one/venv/lib/python3.7/site-packages/Adafruit_IO/client.py", line 118, in _get self._handle_error(response) File "/Users/zeyad/PycharmProjects/one/venv/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 - that is an invalid URL, please check the API documentation at https://io.adafruit.com/api/docs to make sure your URL is correct

brentru commented 5 years ago

I tested this morning with the latest version of Adafruit IO Python installed directly from this repository and was unable to reproduce the 404 error. I ran the code against a feed which exists, and a feed which doesn't exist, and was able to write to both (in the instance of the feed which did not exist, it was created as expected).

Please make sure you're using the latest version of Adafruit IO Python with a valid active key and username