TypeError while trying to write data to influxDB

Hi there,
I’m trying to write simple data to the influxDB using HTTP-post-request.
The hardware is an NodeMCU-ESP32 DEVKITV1 and I use the latest version of Zerynth Studio (r2.2.0-p02)

import requests
for i in range(3):
try:
url = “http://xxx.xxx.xx.xxx:8086/write?db=Database&u=user&p=password
data = {“temperature”: {“value” : 25}}
response = requests.post(url=url, data=data)
break
except Exception as e:
print(e)

I have tried many ways for the transfer of the “data”, but the result is always an TypeError like this:
[TypeError @[0000:01C7:0000:0000:0000:0000:0000:0000]]
(javascript:window.except(’@[0000:01C7:0000:0000:0000:0000:0000:0000]’,'TypeError '))

Are there any known issues with post-requests on this device?

Hi w.khal,
try this way (remove explicit url argument assignment):

response = requests.post(url, data=data)

:slightly_smiling_face:

1 Like

Thanks a lot, this solved the first problem.
After changing the code I’ve got an response.status code: 400 “Bad Request”
I tried to adapt the “data” in different ways, but it always throws an “TypeError” or “400 Bad Request”.
While using Spyder-IDE with Python 3.7.1, I found the following code that works fine, but when using Zerynth it throws an AttributeError like this:
AttributeError @[0063:000B:0069:0017:0000:01C5:0000:0000]

the code is:

try:
url = “http://xxx.xxx.xx.xxx:8086/write?db=database&u=user&p=password
data=“measurement value=25.1”

response = requests.post(url, data=data)
print("Response status %i" % response.status_code)                      # in Zerynth: response.status

except Exception as e:
print(e)

I think the reason is the usage of another library in Zerynth. Is there also any known solution for this issue?

Indeed the Zerynth and Python request libraries are slightly different… Have a look here :slight_smile:

Just print
response.status
instead of
response.status_code
and your code should not throw an attribute error exception anymore.