Python版本- 2.7 InfluxDB版本- 1.5.0
我是一个新手,我正在尝试将我的InfluxDB数据库与Python连接起来,这样我就可以为未来的项目编写代码。
我测试了这个link中的示例程序。(直接代码如下)
from influxdb import InfluxDBClient
json_body = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
]
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'example')
client.create_database('example')
client.write_points(json_body)
result = client.query('select value from cpu_load_short;')
print("Result: {0}".format(result))在运行程序时,我收到这个错误。
Traceback (most recent call last):
File "influxentryexample.py", line 19, in <module>
client.create_database('example')
File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 318, in create_database
status_code=201
File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 124, in request
raise InfluxDBClientError(response.content, response.status_code)
influxdb.client.InfluxDBClientError: 404: 404 page not found发布于 2018-04-12 11:53:20
如果您在不更改其配置文件的情况下安装influxdb,则无需使用用户名和密码即可登录,因此只需键入:
client = influxdb.InfluxDBClient(host='localhost', port=8086)然后,您将在python和influxdb之间建立连接。
但是通过这种方式,您没有指定要在write_points(jsonbody)之前插入数据的数据库。您需要使用client.create_database()和client.switch_database(),如下所示:
client.create_database('example')
client.switch_database('example')但是作为学习者(我也是),你最好学习如何使用restful API请求来做一些work.It将帮助我们理解influxdb是如何工作的
https://stackoverflow.com/questions/49246303
复制相似问题