python3使用requests模塊向influxdb的http API發送接口請求實現數據寫入,以下:html
1. 建立數據庫python
[python] view plain copy數據庫
import requests curl
posturl = 'http://192.168.220.128:8086/query' ide
data = {'q': 'create DATABASE mydb'} post
response = requests.post(posturl, data=data) url
[python] view plain copyspa
print(response.status_code) .net
print(response.headers) code
相似於curl命令以下:
[python] view plain copy
curl -POST http://192.168.220.128:8086/query --data-urlencode "q=CREATE DATABASE mydb"
2. 向庫中寫入數據
[html] view plain copy
import requests
posturl = 'http://192.168.220.128:8086/write?db=mydb'
data="cpu_load_short,host=server01,region=us-west value=0.69"
response = requests.post(posturl, data=data)
[html] view plain copy
print(response.status_code)
print(response.headers)
相似於curl命令以下:
[python] view plain copy
curl -i -XPOST 'http://192.168.220.128:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 '