adafruit / Adafruit_IO_Python

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

Documentation "Send" example fails when Feed contains upper case characters. #123

Closed BusterRaid closed 3 years ago

BusterRaid commented 3 years ago

This occurs on an "emulated" Raspberry Pi.

Guest Operating System: Raspberry Pi Debian GNU/Linux 9.13 Kernel: Linux 4.9.0-13-amd64 Architecture: x86-64

Using a Feed name which contains any upper case characters results in an error response, when following the "Quickstart" documentation, e.g: Create a Feed via the GUI OR programmatically called "Foo". Attempt to programmatically send data to the feed "foo" succeeds:

aio = Client(G_AdaUser, G_AdaKey)
aio.send('foo', 100)

Attempt to programmatically send data to the feed "Foo" fails: aio.send('Foo', 100)

Documentation shows an example where a mixed case name is used:

[]https://adafruit-io-python-client.readthedocs.io/en/latest/quickstart.html?highlight=send#quickstart(url)

... In this case the name "Foo" is suggested by the documentation as a suitable Feed name, but this would actually fail.

brentru commented 3 years ago

@BusterRaid Feeds are referenced by their keys, not their names. What's the feed's key on Adafruit IO?

brentru commented 3 years ago

Closing for now, please re-open if you have further clarification for what should be changed in the documentation

MS3FGX commented 3 years ago

@brentru Think I've run into the same problem OP is describing. I can create a feed name with capital letters and push data to it, but when I try to access it again I receive a "400 Bad Request" error. As an example, the following code runs as expected the first time, but results in an error if it's run a second time:

from Adafruit_IO import Client, Feed, RequestError

ADAFRUIT_IO_USERNAME = 'MS3FGX'
ADAFRUIT_IO_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

feedname = "TEST"

try:
    feed = aio.feeds(feedname)
except RequestError:
    feed = aio.create_feed(Feed(name=feedname))

aio.send_data(feed.key, "1234")

The error is especially confusing since I can see that the "TEST" feed has been created on the IO page, and that the data has been received. If I change the "feedname" variable to "test", not only does the error go away, but the data ends up in the original "TEST" feed.

Perhaps this is intended behavior, but it's not very intuitive. Logically, whatever name I use to create the feed should work when I want to access it later.