diff --git a/.circleci/config.yml b/.circleci/config.yml index 023f024..866544b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -100,7 +100,7 @@ jobs: name: Checks that the description will render correctly on PyPI. command: | pip install --upgrade pip - pip install twine --user + pip install 'twine>=5.1,<6.1' --user python setup.py sdist bdist_wheel twine check dist/* check-docstyle: diff --git a/CHANGELOG.md b/CHANGELOG.md index d0edcb3..c45753f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 1.11.0 [unreleased] +### Bug Fixes + +1. [#119](https://github.com/InfluxCommunity/influxdb3-python/pull/119): Fix use of `proxy` argument in client and query_api to use in channel solution for GRPC proxy. + ## 0.10.0 [2024-11-27] ### Bug Fixes diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py index 9097b31..40ab8a4 100644 --- a/influxdb_client_3/__init__.py +++ b/influxdb_client_3/__init__.py @@ -121,7 +121,7 @@ def __init__( possible. :key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128) :key str proxy_headers: A dictionary containing headers that will be sent to the proxy. Could be used for proxy - authentication. + authentication. (Applies to Write API only) :key int connection_pool_maxsize: Number of connections to save that can be reused by urllib3. Defaults to "multiprocessing.cpu_count() * 5". :key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests @@ -166,7 +166,8 @@ def __init__( else: connection_string = f"grpc+tcp://{hostname}:{port}" self._query_api = _QueryApi(connection_string=connection_string, token=token, - flight_client_options=flight_client_options) + flight_client_options=flight_client_options, + proxy=kwargs.get("proxy", None)) def write(self, record=None, database=None, **kwargs): """ diff --git a/influxdb_client_3/query/query_api.py b/influxdb_client_3/query/query_api.py index 3b36d20..7d03a95 100644 --- a/influxdb_client_3/query/query_api.py +++ b/influxdb_client_3/query/query_api.py @@ -25,7 +25,8 @@ class QueryApi(object): def __init__(self, connection_string, token, - flight_client_options) -> None: + flight_client_options, + proxy=None) -> None: """ Initialize defaults. @@ -35,9 +36,12 @@ def __init__(self, """ self._token = token self._flight_client_options = flight_client_options or {} + self._proxy = proxy self._flight_client_options["generic_options"] = [ ("grpc.secondary_user_agent", USER_AGENT) ] + if self._proxy: + self._flight_client_options["generic_options"].append(("grpc.http_proxy", self._proxy)) self._flight_client = FlightClient(connection_string, **self._flight_client_options) def query(self, query: str, language: str, mode: str, database: str, **kwargs): diff --git a/tests/test_query.py b/tests/test_query.py index 0ad7e3f..1c6ab43 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -150,3 +150,17 @@ def test_query_with_parameters(self): ) mock_do_get.assert_called_once_with(expected_ticket, ANY) + + def test_query_proxy_base_client(self): + test_proxy = "http://testproxy:5432" + client = InfluxDBClient3( + host="http://localhost:8443", + token="my-token", + org="my-org", + database="my-database", + proxy=test_proxy + ) + + assert client._query_api._proxy == test_proxy + assert ('grpc.http_proxy', test_proxy) in\ + client._query_api._flight_client_options.get('generic_options')