Query data from influxdb and store in a python data frame

I just started using Influxdb client for python and I’m kind of lost on how to access influxdb data base (on a remote server) in order to query some data from it and store the imported data in a data frame.

I found in the documentation, the following lines to access influxdb of a remote host and to query the data:

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

client.query(‘SELECT “duration” FROM “pyexample”.“autogen”.“brushEvents” WHERE time > now() - 4d GROUP BY “user”’)

My problem:

1- I don’t know how to get the ‘host’ and ‘port’ values for the remote host.
2-I don’t know how to store the imported data in a python data frame.

Thanks in advance

Hello @ThePheonix,
What version of InfluxDB are you using? Just checking are you using this client, it’s the only one that is supported? https://github.com/influxdata/influxdb-client-python

Please look at InfluxDB 1.8 compatibility:

How and where are you running InfluxDB remotely? If you’re using InfluxDB Cloud for example, your client would look like this for 1.8:
username = ‘username’
password = ‘password’

database = ‘telegraf’
retention_policy = ‘autogen’

bucket = f’{database}/{retention_policy}’
client = InfluxDBClient(url=“https://us-west-2-1.aws.cloud2.influxdata.com/”, token=f’{username}:{password}’, org=’-’)

hi @Anaisdg thank you for your answer :slight_smile:
I am using InfluxDB version 1.8.2.
I can access a remote server using TeamViewer, there it’s easy for me to access the databases on influxdb.
However I would like to access these databases from my local machine (without logging in on TeamViewer) using the InfluxDB python client. I can get the IP address of the remote server.
But if I try to do this:

 from influxdb import InfluxDBClient, DataFrameClient  

I get this error:

ConnectionError: HTTPConnectionPool(host=‘169.XXXXXX’, port=8086): Max retries exceeded with url: /query?q=SHOW+DATABASES (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x000001FC55786BC8>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond’))

Do you have any ideas, what could be the problem?

Hello. @ThePheonix,
It looks like you’re using the wrong client. Can you please try using the client above instead?
Thank you.