I am able to write to cloud serverless using the Influxdb client 3 using:
import os, time
from influxdb_client_3 import InfluxDBClient3, Point
org = "Tide Alerts"
host = "https://us-east-1-1.aws.cloud2.influxdata.com"
token = "myKey"
bucket = "tutorial"
client = InfluxDBClient3(host=host, token=token, org=org)
database="tutorial"
data = {
"point1": {
"location": "Klamath",
"species": "bees",
"count": 23,
},
"point2": {
"location": "Portland",
"species": "ants",
"count": 30,
},
"point3": {
"location": "Klamath",
"species": "bees",
"count": 28,
},
"point4": {
"location": "Portland",
"species": "ants",
"count": 32,
},
"point5": {
"location": "Klamath",
"species": "bees",
"count": 29,
},
"point6": {
"location": "Portland",
"species": "ants",
"count": 40,
},
}
for key in data:
point = (
Point("census")
.tag("location", data[key]["location"])
.field(data[key]["species"], data[key]["count"])
)
client.write(database=database, record=point)
time.sleep(1) # separate points by 1 second
print("Complete. Return to the InfluxDB UI.")
but when I try and read using:
query = """SELECT *
FROM 'census'
WHERE time >= now() - interval '24 hours'
AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)"""
# Execute the query
table = client.query(query=query, database="tutorial", language='sql')
# Convert to dataframe
df = table.to_pandas().sort_values(by="time")
print(df)
I get the following error:
---------------------------------------------------------------------------
FlightUnavailableError Traceback (most recent call last)
Cell In[4], line 7
1 query = """SELECT *
2 FROM 'census'
3 WHERE time >= now() - interval '24 hours'
4 AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)"""
6 # Execute the query
----> 7 table = client.query(query=query, database="tutorial", language='sql')
9 # Convert to dataframe
10 df = table.to_pandas().sort_values(by="time")
File c:\Users\rober\Dropbox\Jupyter\.venv\Lib\site-packages\influxdb_client_3\__init__.py:267, in InfluxDBClient3.query(self, query, language, mode, database, **kwargs)
264 database = self._database
266 try:
--> 267 return self._query_api.query(query=query, language=language, mode=mode, database=database, **kwargs)
268 except InfluxDBError as e:
269 raise e
File c:\Users\rober\Dropbox\Jupyter\.venv\Lib\site-packages\influxdb_client_3\query\query_api.py:97, in QueryApi.query(self, query, language, mode, database, **kwargs)
95 return mode_func() if callable(mode_func) else mode_func
96 except Exception as e:
---> 97 raise e
File c:\Users\rober\Dropbox\Jupyter\.venv\Lib\site-packages\influxdb_client_3\query\query_api.py:81, in QueryApi.query(self, query, language, mode, database, **kwargs)
...
File c:\Users\rober\Dropbox\Jupyter\.venv\Lib\site-packages\pyarrow\_flight.pyx:1708, in pyarrow._flight.FlightClient.do_get()
File c:\Users\rober\Dropbox\Jupyter\.venv\Lib\site-packages\pyarrow\_flight.pyx:68, in pyarrow._flight.check_flight_status()
FlightUnavailableError: Flight returned unavailable error, with message: empty address list: . gRPC client debug context: UNKNOWN:empty address list: {grpc_status:14, created_time:"2025-01-17T19:48:39.8809075+00:00"}. Client context: IOError: Server never sent a data message. Detail: Internal
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
Any idea what I am doing wrong? I am able to query sucessfully using flux with the older"InfluxDBClient". This works for example:
import pandas as pd
from influxdb_client import InfluxDBClient
from datetime import datetime, timezone
import time
influxdb_client = InfluxDBClient(host, token, org)
query_api = influxdb_client.query_api()
# Flux query for last 24 hours of data
query = '''
from(bucket: "tutorial")
|> range(start: -1h)
|> limit(n:1)
'''
# Execute query
result = influxdb_client.query_api().query(query=query, org="your-org")
# Convert to dataframe
df = pd.DataFrame([{
'time': record.get_time(),
**{k: v for k, v in record.values.items() if k != '_time'}
} for table in result for record in table])
print(df)