0

I am trying to query data from the Influx database through pandas using the following code:

from influxdb_client import InfluxDBClient
import pandas as pd

my_token = "my_token"
my_org = "my_org"
bucket = "bucket"

query= '''
from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement")
  |> filter(fn: (r) => r["_field"] == "count")
  |> filter(fn: (r) => r["unit"] == "unit")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")'''

username = 'username'
password = 'password'

client = InfluxDBClient(url="https://us-west-2-1.aws.cloud2.influxdata.com/", token=f'{username}:{password}', org='my_org')

system_stats = client.query_api().query_data_frame(org=my_org, query=query)

After executing the above, I get an error: ApiException: (0) Reason: SSLError [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

I am not familiar with the Influx database but I need to query some data and create a dataframe. Is the syntax I am using right? How should I fix this? Thank you!

1 Answer 1

1

Try with certifi:

import certifi

client = InfluxDBClient(
    url='https://us-west-2-1.aws.cloud2.influxdata.com',
    token=f'{username}:{password}', org=my_org,
    ssl_ca_cert=certifi.where()
)

Inspired by this github issue

Or use verify_ssl=False as parameter of InfluxDBClient but it's not a good idea.

Sign up to request clarification or add additional context in comments.

4 Comments

In both cases, I get the following error: ApiException: (401) Reason: Unauthorized. HTTP response body: b'{"code":"unauthorized","message":"unauthorized access"}'
Not exactly sure what that means
It means your original problem is solved :) The SSL connection is now established. However, the new problem is your token. Maybe you should pass token=my_token instead of token=f'{username}:{password}'
Thanks for the help! Turns out the url is wrong and a different token is needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.