【问题标题】:InfluxDB Python ConnectionInfluxDB Python 连接
【发布时间】:2018-03-13 00:07:36
【问题描述】:

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

【问题讨论】:

标签: python influxdb


【解决方案1】:

如果您安装 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 request来做一些工作。这将有助于我们了解influxdb是如何工作的

【讨论】:

    猜你喜欢
    • 2014-12-10
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 2019-08-08
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多