From 4377572e2d84d696bd2ba11311198330c91df5c2 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Sat, 11 Apr 2026 09:31:27 +0700 Subject: [PATCH 1/5] test: fix parser and redirect test case --- influxdb_client/client/flux_csv_parser.py | 10 ++++++++++ tests/test_WriteApi.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/influxdb_client/client/flux_csv_parser.py b/influxdb_client/client/flux_csv_parser.py index 99e68094..6d8fa76c 100644 --- a/influxdb_client/client/flux_csv_parser.py +++ b/influxdb_client/client/flux_csv_parser.py @@ -251,6 +251,16 @@ def _prepare_data_frame(self): # We have to create temporary DataFrame because we want to preserve default column values _temp_df = pd.DataFrame(self._data_frame_values) + # This is for backward compatibles reason + # In newer Pandas versions 'string' type will be 'str', in older versions 'string' type will be 'object' + # In newer Pandas versions 'time' will be 'datetime64[us, UTC]', in older versions 'time' + # will be 'datetime64[ns, UTC]' + for column in _temp_df.columns: + if _temp_df[column].dtype.name == 'str': + _temp_df[column] = _temp_df[column].astype(object) + if _temp_df[column].dtype.name == 'datetime64[us, UTC]': + _temp_df[column] = _temp_df[column].astype('datetime64[ns, UTC]') + self._data_frame_values = [] # Custom DataFrame index diff --git a/tests/test_WriteApi.py b/tests/test_WriteApi.py index b2cc7ca7..73832db6 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -532,7 +532,8 @@ def test_redirect(self): Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT self.influxdb_client.close() - self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org") + retries = Retry(redirect=1, remove_headers_on_redirect=[]) + self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries) httpretty.register_uri(httpretty.POST, uri="http://localhost2/api/v2/write", status=204) httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=301, From 8ebfa5335731d1321a44a480e1ec66aef07ffc66 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Mon, 13 Apr 2026 08:49:31 +0700 Subject: [PATCH 2/5] refactor: remove unused code --- tests/test_WriteApi.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_WriteApi.py b/tests/test_WriteApi.py index 73832db6..9ae94b93 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -528,8 +528,6 @@ def test_writes_default_tags_dict_without_tag(self): def test_redirect(self): from urllib3 import Retry - Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset() - Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT self.influxdb_client.close() retries = Retry(redirect=1, remove_headers_on_redirect=[]) @@ -548,9 +546,6 @@ def test_redirect(self): self.assertEqual('Token my-token', requests[0].headers['Authorization']) self.assertEqual('Token my-token', requests[1].headers['Authorization']) - from urllib3 import Retry - Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT - def test_named_tuple(self): httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204) From 7dff09381e55582825016c1e419796e58c80bba6 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Mon, 13 Apr 2026 09:01:20 +0700 Subject: [PATCH 3/5] refactor: revert code --- tests/test_WriteApi.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_WriteApi.py b/tests/test_WriteApi.py index 9ae94b93..1748f76b 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -528,8 +528,12 @@ def test_writes_default_tags_dict_without_tag(self): def test_redirect(self): from urllib3 import Retry + Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset() + Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT self.influxdb_client.close() + # In the newer urllib3 versions we need to set `redirect` and `remove_headers_on_redirect=[]` to + # make it re-direct POST requests and stop it from remove the `Authorization` header. retries = Retry(redirect=1, remove_headers_on_redirect=[]) self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries) @@ -546,6 +550,9 @@ def test_redirect(self): self.assertEqual('Token my-token', requests[0].headers['Authorization']) self.assertEqual('Token my-token', requests[1].headers['Authorization']) + from urllib3 import Retry + Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT + def test_named_tuple(self): httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204) From bc076cad8a2e03808e5b9d309c9f92ffb054c5e1 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Mon, 13 Apr 2026 09:06:46 +0700 Subject: [PATCH 4/5] chore: update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b541dcf..613eaeb6 100644 --- a/README.md +++ b/README.md @@ -1097,13 +1097,20 @@ with InfluxDBClient(url="http://localhost:8086", If your proxy notify the client with permanent redirect (`HTTP 301`) to **different host**. The client removes `Authorization` header, because otherwise the contents of `Authorization` is sent to third parties which is a security vulnerability. -You can change this behaviour by: +You can change this behavior by doing this in older urllib3 versions: ``` python from urllib3 import Retry Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset() Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT ``` +In the newer urllib3 versions, try to use this: + +``` python +retries = Retry(redirect=1, remove_headers_on_redirect=[]) +self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries) +``` + ### Delete data From ead668eba1456559f60f8010c27b9898ac1c9b06 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 15 Apr 2026 10:34:55 +0700 Subject: [PATCH 5/5] docs: update code comments --- README.md | 6 ++++-- tests/test_WriteApi.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 613eaeb6..fa9fe8a8 100644 --- a/README.md +++ b/README.md @@ -1097,14 +1097,16 @@ with InfluxDBClient(url="http://localhost:8086", If your proxy notify the client with permanent redirect (`HTTP 301`) to **different host**. The client removes `Authorization` header, because otherwise the contents of `Authorization` is sent to third parties which is a security vulnerability. -You can change this behavior by doing this in older urllib3 versions: +You can change this behavior by doing this in older urllib3 versions < 2.5.0 : ``` python from urllib3 import Retry Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset() Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT ``` -In the newer urllib3 versions, try to use this: + +In the newer urllib3 versions >= 2.5.0, try to use this for redirect requests and stop urllib3 from +removing the `Authorization` header: : ``` python retries = Retry(redirect=1, remove_headers_on_redirect=[]) diff --git a/tests/test_WriteApi.py b/tests/test_WriteApi.py index 1748f76b..32be8e0c 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -532,7 +532,7 @@ def test_redirect(self): Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT self.influxdb_client.close() - # In the newer urllib3 versions we need to set `redirect` and `remove_headers_on_redirect=[]` to + # In the newer urllib3 versions >= 2.5.0 we need to set `redirect` and `remove_headers_on_redirect=[]` to # make it re-direct POST requests and stop it from remove the `Authorization` header. retries = Retry(redirect=1, remove_headers_on_redirect=[]) self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries)