Skip to content

IPv6 hosts fail #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oclyke opened this issue Apr 30, 2025 · 0 comments
Open

IPv6 hosts fail #135

oclyke opened this issue Apr 30, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@oclyke
Copy link

oclyke commented Apr 30, 2025

Specifications

  • Client Version: 0.12.0, 0.13.0-dev0, 0.13.0-dev0-with-patch-132
  • InfluxDB Version: influxdb3 3.0.1, revision e684fc1a249d5dd8564462b85e0a49f49de6b109
  • Platform: OSX (darwin)

IPv6 host strings do not work.

Working, with host using IPv4 (everything is standard)

(venv) oclyke@maggotbrain influxdb3-python % env | grep INFLUX
INFLUXDB_HOST=http://127.0.0.1:8082
INFLUXDB_TOKEN=apiv3_hD5DEQJMIN2B61WNNd3oOUb_f8asn5ta804WCNnToGDHP2zBszXD2fgjpzFhBbMK1hvVflRy7NNT1aKYkTFfoA
(venv) oclyke@maggotbrain influxdb3-python % python Examples/query_async.py
...
[success]

Changing host to use IPv6 causes an error.
In version 0.12.0 and in the latest main branch (0.13.0) the first error which is encountered has to do with the way the connection string is assembled after the host and port are parsed (IPv6 loopback address ::1 requires brackets in the connection string to disambiguate)

(venv) oclyke@maggotbrain influxdb3-python % export INFLUXDB_HOST=http://[::1]:8082
(venv) oclyke@maggotbrain influxdb3-python % env | grep INFLUX                     
INFLUXDB_HOST=http://[::1]:8082
INFLUXDB_TOKEN=apiv3_hD5DEQJMIN2B61WNNd3oOUb_f8asn5ta804WCNnToGDHP2zBszXD2fgjpzFhBbMK1hvVflRy7NNT1aKYkTFfoA
(venv) oclyke@maggotbrain influxdb3-python % python Examples/query_async.py
Traceback (most recent call last):
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/Examples/query_async.py", line 87, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/Examples/query_async.py", line 71, in main
    client = InfluxDBClient3(
        host=config.host,
    ...<2 lines>...
        org=config.org
    )
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/__init__.py", line 177, in __init__
    self._query_api = _QueryApi(connection_string=connection_string, token=token,
                      ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                flight_client_options=flight_client_options,
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                proxy=kwargs.get("proxy", None), options=q_opts_builder.build())
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/query/query_api.py", line 149, in __init__
    self._flight_client = FlightClient(connection_string, **self._flight_client_options)
                          ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyarrow/_flight.pyx", line 1405, in pyarrow._flight.FlightClient.__init__
  File "pyarrow/_flight.pyx", line 635, in pyarrow._flight.Location.__init__
  File "pyarrow/_flight.pyx", line 78, in pyarrow._flight.check_flight_status
  File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Cannot parse URI: 'grpc+tcp://::1:8082' due to syntax error at character '' (position 19)

After #132 this syntax error is resolved but there appears to be an underlying issue with PyArrow.
As far as I can tell PyArrow is relying on gRPC which supports IPv6 hosts just like this.
Here's the error I find after resolving the syntax error (by detecting IPv6 and adding square brackets around the IP address in the connection string)

(venv) oclyke@maggotbrain influxdb3-python % python Examples/query_async.py
Traceback (most recent call last):
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connection.py", line 198, in _new_conn
    sock = connection.create_connection(
        (self._dns_host, self.port),
    ...<2 lines>...
        socket_options=self.socket_options,
    )
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
    ~~~~~~~~~~~~^^^^
ConnectionRefusedError: [Errno 61] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/Examples/query_async.py", line 87, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/Examples/query_async.py", line 78, in main
    write_data(client, measurement)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/Examples/query_async.py", line 52, in write_data
    client.write(data)
    ~~~~~~~~~~~~^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/__init__.py", line 206, in write
    self._write_api.write(bucket=database, record=record, **kwargs)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/client/write_api.py", line 377, in write
    results = list(map(write_payload, payloads.items()))
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/client/write_api.py", line 375, in write_payload
    return self._post_write(_async_req, bucket, org, final_string, payload[0])
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/client/write_api.py", line 520, in _post_write
    return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                          async_req=_async_req,
                                          ^^^^^^^^^^^^^^^^^^^^^
                                          content_type="text/plain; charset=utf-8",
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                          **kwargs)
                                          ^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/service/write_service.py", line 60, in post_write
    (data) = self.post_write_with_http_info(org, bucket, body, **kwargs)  # noqa: E501
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/service/write_service.py", line 90, in post_write_with_http_info
    return self.api_client.call_api(
           ~~~~~~~~~~~~~~~~~~~~~~~~^
        '/api/v2/write', 'POST',
        ^^^^^^^^^^^^^^^^^^^^^^^^
    ...<12 lines>...
        collection_formats={},
        ^^^^^^^^^^^^^^^^^^^^^^
        urlopen_kw=kwargs.get('urlopen_kw', None))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/_sync/api_client.py", line 343, in call_api
    return self.__call_api(resource_path, method,
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
                           path_params, query_params, header_params,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
                           _return_http_data_only, collection_formats,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                           _preload_content, _request_timeout, urlopen_kw)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/_sync/api_client.py", line 173, in __call_api
    response_data = self.request(
        method, url, query_params=query_params, headers=header_params,
        post_params=post_params, body=body,
        _preload_content=_preload_content,
        _request_timeout=_request_timeout, **urlopen_kw)
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/_sync/api_client.py", line 388, in request
    return self.rest_client.POST(url,
           ~~~~~~~~~~~~~~~~~~~~~^^^^^
                                 query_params=query_params,
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
                                 body=body,
                                 ^^^^^^^^^^
                                 **urlopen_kw)
                                 ^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/_sync/rest.py", line 311, in POST
    return self.request("POST", url,
           ~~~~~~~~~~~~^^^^^^^^^^^^^
                        headers=headers,
                        ^^^^^^^^^^^^^^^^
    ...<4 lines>...
                        body=body,
                        ^^^^^^^^^^
                        **urlopen_kw)
                        ^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/write_client/_sync/rest.py", line 220, in request
    r = self.pool_manager.request(
        method, url,
    ...<3 lines>...
        headers=headers,
        **urlopen_kw)
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/_request_methods.py", line 143, in request
    return self.request_encode_body(
           ~~~~~~~~~~~~~~~~~~~~~~~~^
        method, url, fields=fields, headers=headers, **urlopen_kw
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/_request_methods.py", line 278, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/poolmanager.py", line 443, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
        method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    )
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/util/retry.py", line 449, in increment
    raise reraise(type(error), error, _stacktrace)
          ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/util/util.py", line 39, in reraise
    raise value
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
        conn,
    ...<10 lines>...
        **response_kw,
    )
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connectionpool.py", line 493, in _make_request
    conn.request(
    ~~~~~~~~~~~~^
        method,
        ^^^^^^^
    ...<6 lines>...
        enforce_content_length=enforce_content_length,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connection.py", line 445, in request
    self.endheaders()
    ~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1331, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1091, in _send_output
    self.send(msg)
    ~~~~~~~~~^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1035, in send
    self.connect()
    ~~~~~~~~~~~~^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connection.py", line 276, in connect
    self.sock = self._new_conn()
                ~~~~~~~~~~~~~~^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/venv/lib/python3.13/site-packages/urllib3/connection.py", line 213, in _new_conn
    raise NewConnectionError(
        self, f"Failed to establish a new connection: {e}"
    ) from e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x107b53230>: Failed to establish a new connection: [Errno 61] Connection refused

For a sanity check I restored the host env variable to using IPv4 (retaining the changes from #132) and the example still works.

(venv) oclyke@maggotbrain influxdb3-python % export INFLUXDB_HOST=http://127.0.0.1:8082
(venv) oclyke@maggotbrain influxdb3-python % env | grep INFLUX                         
INFLUXDB_HOST=http://127.0.0.1:8082
INFLUXDB_TOKEN=apiv3_hD5DEQJMIN2B61WNNd3oOUb_f8asn5ta804WCNnToGDHP2zBszXD2fgjpzFhBbMK1hvVflRy7NNT1aKYkTFfoA
(venv) oclyke@maggotbrain influxdb3-python % python Examples/query_async.py            
2
query start:    2025-04-30 04:23:42.180373
query returned: 2025-04-30 04:23:42.281186
3
5
8
13
21
34
55
89
144
fibio sequence = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
data set =
           alt     bearing     id       speed                       time
0   471.661026  273.311606  sgw22   90.523038 2025-04-30 04:23:32.095047
1   585.998457  331.069485  sgw22   38.872012 2025-04-30 04:23:22.095047
2    90.426394  259.641275   s3b1  204.117649 2025-04-30 04:23:12.095047
3  1641.940021  240.643727  sgw22  192.625260 2025-04-30 04:23:02.095047
4  1366.394403  177.839222  sgw22   67.851462 2025-04-30 04:22:52.095047
5    15.969212   27.333820   s3b1  279.339632 2025-04-30 04:22:42.095047
6  1965.781570   64.524343   dq41   49.413279 2025-04-30 04:22:32.095047
7   153.724868  335.828109   s3b1  200.806884 2025-04-30 04:22:22.095047
8   465.889100  178.168580   s3b1  160.161497 2025-04-30 04:22:12.095047
9    14.450779  177.070938   dq41   12.042853 2025-04-30 04:22:02.095047

Now, getting a bit further off the beaten path, here's an error encountered from PyArrow under the environment of this repository with #132 applied.

  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/__init__.py", line 317, in query_async
    return await self._query_api.query_async(query=query,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/query/query_api.py", line 199, in query_async
    raise e
  File "/Users/oclyke/Documents/github/InfluxCommunity/influxdb3-python/influxdb_client_3/query/query_api.py", line 193, in query_async
    _flight_reader = await loop.run_in_executor(None,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/b0h8ixs9h67c1ap0fa9kncyvpdvvk05y-python3-3.12.8/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyarrow/_flight.pyx", line 1708, in pyarrow._flight.FlightClient.do_get
  File "pyarrow/_flight.pyx", line 68, in pyarrow._flight.check_flight_status
pyarrow._flight.FlightUnavailableError: Flight returned unavailable error, with message: failed to connect to all addresses;
last error: UNKNOWN: ipv6:%5B::1%5D:8082: Failed to connect to remote host: Connection refused.
gRPC client debug context: UNKNOWN:failed to connect to all addresses;
last error: UNKNOWN: ipv6:%5B::1%5D:8082: Failed to connect to remote host: Connection refused {created_time:"2025-04-29T21:08:47.45304-07:00", grpc_status:14}. 
Client context: IOError: Server never sent a data message. Detail: Internal

Code sample to reproduce problem

This issue is reproduced using the example Examples/query_async.py when using an IPv6 loopback address as the host, i.e. export INFLUXDB_HOST=http://[::1]:8082

Depending on whether or not #132 is applied there will be one of two issues:

  • Without: a syntax error is encountered with the assembled connection string "grpc+tcp://::1:8082"
  • With: a connection error due to "connection refused"

Expected behavior

IPv6 ip addresses should be supported in the host string, e.g.

from influxdb_client_3 import InfluxDBClient3

client = InfluxDBClient3(
    host="http://[::1]:8082",
    database="my-db",
)

Actual behavior

Connection error thrown after working through syntax error.

Additional info

No response

@oclyke oclyke added the bug Something isn't working label Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant