1

Could I anyone explain how I can use requests in Python to send this CURL:

curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'

I dont know how to parse it into a sample code. Thanks a lot

thien nguyen
  • 306
  • 5
  • 10
  • Please look at http://stackoverflow.com/questions/31061227/curl-vs-python-requests-when-hitting-apis - duplicate. Also http://stackoverflow.com/questions/25797455/how-to-use-requests-python-module-to-make-curl-calls – dmitryro Jun 29 '16 at 02:43
  • That doesn't help, as it still doesn't cldearly show how to do it for this. – Kuzon Apr 03 '17 at 18:38

2 Answers2

4
import requests

url_string = 'http://localhost:8086/write?db=mydb'
data_string = 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'

r = requests.post(url_string, data=data_string)
Davide
  • 75
  • 7
  • Thanks, this worked well. What if we want to do this: curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb" – Eradicatore Oct 23 '18 at 15:18
0

To create a InfluxDB via Python3:

#!/usr/bin/env python3
import urllib.request as requests

url = "http://localhost:8086/query"

params = {
"q=CREATE DATABASE mydb"
}

r = requests.Request(url, data=params)
Klaas
  • 1