Page 1 of 1

Post method ESP32

Posted: Mon Nov 05, 2018 10:22 am
by andermutu99
Dear Community;

I am trying to upload data to Adafruit.io using post method of urequests library. I have tried to options. I both I have ensured I am connected to wifi. The first method is this:

Code: Select all

import urequests as requests
import json

url = "https://io.adafruit.com/api/v2/username/feeds/battery/data?X-AIO-Key=XXXXXXX"

data = {
    "value": "88"
}

r = requests.post(url, data=data)
results = r.json()
print (results)
And I am getting this error:
TypeError: object with buffer protocol required
The second option is the following:

Code: Select all

import urequests as requests
import json
import ujson

url = "https://io.adafruit.com/api/v2/andermutu99/feeds/battery/data?X-AIO-Key=3fe2f3eb5e694346b3f9e709b3128182"

data = {
    "value": "88"
}

data = ujson.dumps(data)
r = requests.post(url, data=data)
results = r.json()
print (results)
With this method I am not getting any error with MicroPython, but I the data is not correctly formatted and Adafruit does not recognize it.
{'error': 'request failed - failed to save data to feed battery. param is missing or the value is empty: datum'}
The first method works perfectly in my PC running in Python 2.7.

Please any help or suggestion is highly appreciated.

Thanks a lot,

Ander.

Re: Post method ESP32

Posted: Mon Nov 05, 2018 2:26 pm
by andermutu99
Hi,

I have tried a new method that I have seen searching the Web, but it does not work.

Code: Select all

r = requests.post(URL, json =dict(value = “88“)) 
I get again this error message from Adafruit :
{'error': 'request failed - failed to save data to feed battery. param is missing or the value is empty: datum'}
Please any help is very useful for me.

Thanks in advance.

Re: Post method ESP32

Posted: Mon Nov 05, 2018 6:09 pm
by pythoncoder
See my comment here.