0
votes

I would like to know how to convert a cURL command into a python request. Indeed, I am using this cURL command :

curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'air_quality,host=raspberrypi value=200'

So, it allows to write the value 200 in the database mydb. But I would like to put this command in a python script. Then, it's not possible to do it, I got a format error.

I think it is possible to do it with python but I don't know how exactly. First, I have to import that :

import requests

Then the command should be like that :

requests.post("htp://localhost:8086/write?db=mydb air_quality,host=raspberrypi value="+str(sensor_value))

My question is : how to write correctly the previous line for the python request ? This a screenshot of my error : Troubleshooting

1

1 Answers

0
votes

@Jack I found the answer, the right command is :

 payload='air_quality,host=raspberrypi value=100'
 requests.post(url="http://localhost:8086/write?db=mydb", data=payload)

I checked in the influxdb database mydb and this is working, meanwhile I would like to get back the values from a sensor, the value is written in the variable sensor_value. How to get it ? I tried this :

payload='air_quality,host=raspberrypi value=sensor_value'

And I got this error : {"error":"unable to parse 'air_quality,host=raspberrypi value=sensor_value': invalid boolean"}