Python influxdb_client_3 query error (tutorial code)

Hello,

When going through the python tutorial for influxdb3, the query function throws an error:

code:
query = “”“SELECT *
FROM ‘census’
“””
table = client.query(query=query, database=“database_name”, language=‘sql’)
df = table.to_pandas().sort_values(by=“time”)
print(df)

error for client.query:
“FlightUnavailableError: Flight returned unavailable error, with message: empty address list: . gRPC client debug context: UNKNOWN:empty address list: {grpc_status:14, created_time:“2024-05-03T13:21:43.074492532+00:00”}. Client context: IOError: Server never sent a data message. Detail: Internal”

I am using the code provided by the tutorial and writing data works.

Any help would be much appreciated!

Hello @Cyrillllll
Can you please share your entire script?
You also have excess quotes

Thank you!

Hello @Anaisdg

When i log in on InfluxDB Cloud and select Query Data and then view guide (application code, python), there is a tutorial and i more or less copy pasted code from there.
These blocks run just fine:

import os, time
from influxdb_client_3 import InfluxDBClient3, Point

host = “https://eu-central-1-1.aws.cloud2.influxdata.com
client = InfluxDBClient3(host=host, token=my_token, org=my_organisation)

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=my_database, record=point)
time.sleep(1) # separate points by 1 second

print(“Complete. Return to the InfluxDB UI.”)

I get a message on the website that the database receives data.
the following block doesn’t work:

query = “”“SELECT *
FROM ‘census’
“””

table = client.query(query=query, database=my_database, language=‘sql’)
df = table.to_pandas().sort_values(by=“time”)
print(df)

error_message:
{
“name”: “FlightUnavailableError”,
“message”: “Flight returned unavailable error, with message: empty address list: . gRPC client debug context: UNKNOWN:empty address list: {grpc_status:14, created_time:"2024-05-05T13:09:44.314680034+00:00"}. Client context: IOError: Server never sent a data message. Detail: Internal”,
“stack”: "---------------------------------------------------------------------------
FlightUnavailableError Traceback (most recent call last)
Cell In[3], line 6
1 query = """SELECT *
2 FROM ‘census’
3 """
5 # Execute the query
----> 6 table = client.query(query=query, database=my_database, language=‘sql’)
8 # Convert to dataframe
9 df = table.to_pandas().sort_values(by="time")

File c:\Users\Cyrill\anaconda3\envs\ada\lib\site-packages\influxdb_client_3\init.py:257, in InfluxDBClient3.query(self, query, language, mode, database, **kwargs)
255 return mode_func() if callable(mode_func) else mode_func
256 except Exception as e:
→ 257 raise e

File c:\Users\Cyrill\anaconda3\envs\ada\lib\site-packages\influxdb_client_3\init.py:243, in InfluxDBClient3.query(self, query, language, mode, database, **kwargs)
241 ticket_data = {"database": database, "sql_query": query, "query_type": language}
242 ticket = Ticket(json.dumps(ticket_data).encode(‘utf-8’))
→ 243 flight_reader = self._flight_client.do_get(ticket, _options)
245 mode_func = {
246 "all": flight_reader.read_all,
247 "pandas": flight_reader.read_pandas,
(…)
252
253 }.get(mode, flight_reader.read_all)
255 return mode_func() if callable(mode_func) else mode_func

File c:\Users\Cyrill\anaconda3\envs\ada\lib\site-packages\pyarrow\_flight.pyx:1633, in pyarrow._flight.FlightClient.do_get()

File c:\Users\Cyrill\anaconda3\envs\ada\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:"2024-05-05T13:09:44.314680034+00:00"}. Client context: IOError: Server never sent a data message. Detail: Internal"
}

Hmm @Cyrillllll,
Thats very odd that you’re able to write with the client and not query with it. The error suggests you’re having an initialization/connection issue with it.

You can also use the pandas mode to return dataframes :slight_smile:

query = "SELECT * FROM census"
pd = client.query(query=query, mode="pandas")
# Print the pandas DataFrame formatted as a Markdown table.
print(pd)

Can you please try that?

@Anaisdg Thanks for the answer! Unfortunately it gives the same error. Reinitiating the client object before querying does not help either.

In the InfluxDBClient3 class (client) of the file called “init.py” , the query method is defined and the last line of this block in the method doesn’t work:

        ticket_data = {"database": database, "sql_query": query, "query_type": language}
        ticket = Ticket(json.dumps(ticket_data).encode('utf-8'))
        flight_reader = self._flight_client.do_get(ticket, _options)

So i’m guessing it has to do with the connection to the database? Is there something i need to change in the settings on the cloud-website?

Yes I’d verify your host, token and org first.

This is working for me:

from influxdb_client_3 import InfluxDBClient3, Point

token = "xxx"
org = "xxx"
host = "https://us-east-1-1.aws.cloud2.influxdata.com/"
database = "test"


client = InfluxDBClient3(
    token=token,
    host=host,
    org=org,
    database=database)


points = [
    Point("home")
            .tag("room", "Kitchen")
            .field("temp", 25.3)
            .field('hum', 20.2)
            .field('co', 9),
    Point("home")
            .tag("room", "Living Room")
            .field("temp", 24.0)
            .field('hum', 20.0)
            .field('co', 5)]

client.write(record=points)
sql = '''Select * from home'''
table = client.query(query=sql, language='sql', mode='pandas')
print(table)

@Anaisdg Hi, I created a new all access token and verified host and organization but the query method still doesn’t work. I copied your code and it runs fine until client.query() and then outputs the same error as before. I tried out the inlfuxdb2 library and that one works for the same token, host and org.

I’m noticing exactly the same error as OP.

just copied pasted all the python code and I get the same error

I’m also experiencing this issue

Hello @kgmuzu @stewart and @pattern,
I have made an issue here:

Please comment on the issue.

The issue was caused by using the influxdb_client_3 with an InfluxDB 2 account. This client is specifically designed to support only InfluxDB 3.

How are we able to evalute the influxdb_cilient_3 as a not yet customer? Is there an option to sign up for a InfluxDB 3 account?

I am running into this same problem while trying to query data from an Influxdb v2 instance which is running locally in a docker container in my laptop, using the influxdb3-client python library.
The purpose of my tests is the recent (as of March 2025) announcement of InfluxQL being favored instead of Flux.
Currently, InfluxDB v3 is not in a state ready for production, so we want to keep using v2 until then, but we’d like to use InfluxQL now and avoid further re-coding in the future.
Recommendation says to use the v3 library, but I have not been able to pass this hurdle yet.

Please see ^that response.
You can query v2 with influxql but it takes a lot of setup. Honestly might be harder than just continuing to query in flux and then changing your queries to influxql with GA.

It also doesn’t support all influxql queries…

1 Like

Thanks Anais, I guess it’s top secret, but is there a rough timeline of when will v3 ready for production?