I am trying to fetch the data from the InfluxDB using the Python InfluxDB-client library but instead of the expected output, I am getting HTML in response.
I am putting the code here.
def get_config(deployment, org=None):
with open('./configs/config.json', 'r') as f:
config = json.load(f)
return config[deployment][org]
try:
config = get_config(deployment, org)
bucket = config['bucket']
org = config['org']
token = config['token']
# Store the URL of your InfluxDB instance
url = config['url']
logger.info("query started")
print(url, token, org)
client = influxdb_client.InfluxDBClient(
url=url,
token=token,
org=org,
timeout=3600*1000 # 30 mins
)
query_api = client.query_api()
logger.info("query executing")
query = f'inst_table = from(bucket: "bucket_name")\
|> range(start: {{start_time}}, stop: {{end_time}})\
|> filter(fn: (r) => r["_measurement"] == "cu_om")\
|> filter(fn: (r) => r["tag_name"] !~ /^$/)\
|> filter(fn: (r) => r["tag_name2"] == "tag_value")\
|> filter(fn: (r) => r["_field"] =~ /^FieldName$)\
|> filter(fn: (r) => r._value > 0)\
|> mean()\
|> duplicate(column: "_stop", as: "_time")\
|> keep(columns: ["_time","_value","_field","tag_name2","tag_name"])\
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")\
|> yield(name:"output")'
query = query.format(start_time='2024-04-22T23:45:00Z',end_time='2024-04-23T23:45:00Z')
print(query)
csv_record = query_api.query_csv(org=org, query=query)
data = [row for row in csv_record]
print(data)
I have verified token, URL, and org is correct. The query is also correct after replacing the start and stop time I am able to see the data inside the InfluxDB but I am not able to see the data using the python code.
Below output I am getting.
[['<!doctype HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width', 'initial-scale=1">
<meta name="description" content="InfluxDB is a time series platform', ' purpose-built by InfluxData for storing metrics and events', ' provides real-time visibility into stacks', ' sensors', ' and systems.">
<title>InfluxDB</title>
<base href="/"><link rel="shortcut icon" href="/favicon.ico">
</head>
<body>
<div id="react-root" data-basepath=""></div>
<script src="/6588f709b0.js"></script></body></html>']]
I am using influxdb-client==1.41.0
for Python.