0

I'm running on error here.. I'm a beginner but I cant figure out what I am missing! The query runs fine on Data Explorer's script editor.

influxdb 2.4 Python 3.10.6 Ubuntu 22.04.1 influxdb_client 1.32.0 (pip install 'influxdb-client[extra]')

I installed the package according to documentation

if this is way too complicated, what is the most common way to write/query data to influxdb? I prefer dataframe format since I am dealing with stocks.

Any help is much appreciated, thank you.

import os
from influxdb_client import InfluxDBClient

token = os.getenv('INFLUXDB_V2_TOKEN')
org = os.getenv('INFLUXDB_V2_ORG')
bucket = os.getenv('INFLUXDB_V2_BUCKET')
url = os.getenv('URL')

client = InfluxDBClient(url=url, token=token,org=org)
query_api = client.query_api()

with client:
    
    """
    Query: using Pandas DataFrame
    """
    df = client.query_data_frame('from(bucket:"{bucket}")' \
                                                ' |> range(start: 0, stop: now())' \
                                                ' |> filter(fn: (r) => r._measurement == "financial-analysis-df")' \
                                                ' |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")' \
                                                ' |> limit(n:10, offset: 0)')
    
print(df.to_string())

"""
Close client
"""
client.close()
grayred8
  • 93
  • 6

1 Answers1

0

I’ve found the problem

the issue is with os. Once I declared the authentication variables in the same file everything worked… I will investigate other authorisation methods.

grayred8
  • 93
  • 6