在python中使用Influxdb客户端-错误:“ InfluxDBClient”对象没有属性“ create_database” /“ get_list_database”

问题描述

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

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。 谢谢

解决方法

您在导入时出错。 InfluxDBClient应该从influxdb导入。 喜欢:

from influxdb import InfluxDBClient

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

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()