diff --git a/CHANGELOG.md b/CHANGELOG.md index 896e452..d2dabfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.13.0 [unreleased] +### Bug Fixes + +1. [#132](https://github.com/InfluxCommunity/influxdb3-python/pull/132): Fixes support for IPv6 addresses in the `host` parameter of the client. The client now correctly handles IPv6 addresses by enclosing them in square brackets. ## 0.12.0 [2025-03-26] diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py index 753a83b..0c48859 100644 --- a/influxdb_client_3/__init__.py +++ b/influxdb_client_3/__init__.py @@ -10,6 +10,8 @@ PointSettings from influxdb_client_3.write_client.domain.write_precision import WritePrecision +from ipaddress import IPv6Address, AddressValueError + polars = importlib.util.find_spec("polars") is not None @@ -147,6 +149,12 @@ def __init__( hostname = parsed_url.hostname if parsed_url.hostname else host port = parsed_url.port if parsed_url.port else 443 + try: + IPv6Address(hostname) + hostname = f"[{hostname}]" + except AddressValueError: + pass + # Construct the clients using the parsed values if write_port_overwrite is not None: port = write_port_overwrite diff --git a/tests/test_influxdb_client_3.py b/tests/test_influxdb_client_3.py index 1b52b76..22b8727 100644 --- a/tests/test_influxdb_client_3.py +++ b/tests/test_influxdb_client_3.py @@ -74,6 +74,29 @@ async def test_query_async(self): assert {'data': 'sql_query', 'reference': query, 'value': -1.0} in result_list assert {'data': 'query_type', 'reference': 'sql', 'value': -1.0} in result_list + @asyncio_run + async def test_query_async_ipv6(self): + with ConstantFlightServer() as server: + client = InfluxDBClient3( + host=f"http://[::1]:{server.port}", + org="my_org", + database="my_db", + token="my_token", + ) + + query = "SELECT * FROM my_data" + + table = await client.query_async(query=query, language="sql") + + result_list = table.to_pylist() + + cd = ConstantData() + for item in cd.to_list(): + assert item in result_list + + assert {'data': 'database', 'reference': 'my_db', 'value': -1.0} in result_list + assert {'data': 'sql_query', 'reference': query, 'value': -1.0} in result_list + assert {'data': 'query_type', 'reference': 'sql', 'value': -1.0} in result_list if __name__ == '__main__': unittest.main()