[Solved] Urequests Adafruit.io

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

[Solved] Urequests Adafruit.io

Post by ioukos » Sat Mar 25, 2017 1:49 pm

Hi guys,

I'm using urequests to send data to Adafruit.io,

Here is my function :

Code: Select all

def postAdafruit(temp):
        url = "https://io.adafruit.com/api/feeds/ThermometreInvercargill/data.json"
        headers = {
                'X-AIO-Key':'myapikeytopsecret',
                'Content-Type': 'application/json'
                }
        payload='{"value": %s }' % str(temp)
        resp= urequests.post(url, data=payload, headers=headers)
        print(resp.text)
        print("Adafruit OK!")

but I got the error:

Code: Select all

NotImplementedError: Redirects not yet supported
What does it mean ?
While the data (basically temperature) is well sent to Adafruit feed.

Do you know a way to discard this error to allow my script to go on ?

Thanks in advance.
Last edited by ioukos on Sat Mar 25, 2017 6:13 pm, edited 1 time in total.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Urequests Adafruit.io

Post by deshipu » Sat Mar 25, 2017 3:33 pm

That means that Adafruit replied with a response that normally tells the browser to visit some other address -- a redirect. And urequests doesn't support that, so you get an exception. If it works for you, you can just catch that exception with a try-except block and ignore it, just make sure to check that it is indeed this one, and not some other, unexpected, exception.

User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

Re: Urequests Adafruit.io

Post by ioukos » Sat Mar 25, 2017 6:12 pm

Hi Deshipu,

I did,

Code: Select all

        try:
                postAdafruit(final_temp)
        except NotImplementedError:
                print("NotImplementedError")
And it works !

Thank you, Adafruit is supposed to send me back my data with a epoch and various other data but I don't really need it ! thank you !

Post Reply