diff --git a/README.md b/README.md index 5b541dcf..fa9fe8a8 100644 --- a/README.md +++ b/README.md @@ -1097,13 +1097,22 @@ 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 < 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 >= 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=[]) +self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries) +``` + ### Delete data 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..32be8e0c 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -532,7 +532,10 @@ 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") + # 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) 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,