Use Influxdb client in python - Error : 'InfluxDBClient' object has no attribute 'create_database'/' get_list_database '

7.8k views Asked by At

I just started using the influxdb client in python. I'm probably doing something wrong but I can't figure it out yet.

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

I get the following errors:

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

Could you please tell me what I'm doing wrong ? Also is there a command line that I can use to know what's my token/url or what's the token/url of a remote host I would like to access. Thanks

1

There are 1 answers

6
fayez On BEST ANSWER

you are making a mistake while importing. InfluxDBClient should be imported from influxdb. like:

from influxdb import InfluxDBClient

also, constructor InfluxDBClient() takes no argument named url and token. as per the doc, the constructor is:

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

so your code should be like this:

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