首页 > 解决方案 > 在 python 中使用 Influxdb 客户端 - 错误:“InfluxDBClient”对象没有属性“create_database”/“get_list_database”

问题描述

我刚开始influxdb在 python 中使用客户端。我可能做错了什么,但我还无法弄清楚。

from influxdb import InfluxDBClient, DataFrameClient  
client=InfluxDBClient(host="localhost",port="8086", username='root')
client.create_database("TEST")

我收到以下错误:

ConnectionError: HTTPConnectionPool(host='localhost', port=8086): Max  retries exceeded with url: /query?q=CREATE+DATABASE+%22TEST%22 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000013E5DD0A8C8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

你能告诉我我做错了什么吗?还有一个命令行,我可以使用它来了解我想要访问的远程主机是什么token/url或远程主机是什么。token/url谢谢

标签: pythondatabasedataframeinfluxdbinfluxdb-python

解决方案


您在导入时犯了一个错误。InfluxDBClient 应该从 influxdb 导入。喜欢:

from influxdb import InfluxDBClient

此外,构造函数InfluxDBClient()不接受名为urland的参数token。根据文档,构造函数是:

InfluxDBClient(host='mydomain.com', port=8086, username='myuser', password='mypass', ssl=True, verify_ssl=True)

所以你的代码应该是这样的:

from influxdb import InfluxDBClient, DataFrameClient  
 
client=InfluxDBClient(host="localhost",port="8086", username='root')
client.create_database("TEST")
client.get_list_database()

推荐阅读