Skip to content

Commit 2b96e56

Browse files
test: fix parser and redirect test case (#704)
1 parent fb5d3f2 commit 2b96e56

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,13 +1097,22 @@ with InfluxDBClient(url="http://localhost:8086",
10971097

10981098
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.
10991099

1100-
You can change this behaviour by:
1100+
You can change this behavior by doing this in older urllib3 versions < 2.5.0 :
11011101

11021102
``` python
11031103
from urllib3 import Retry
11041104
Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset()
11051105
Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT
11061106
```
1107+
1108+
In the newer urllib3 versions >= 2.5.0, try to use this for redirect requests and stop urllib3 from
1109+
removing the `Authorization` header: :
1110+
1111+
``` python
1112+
retries = Retry(redirect=1, remove_headers_on_redirect=[])
1113+
self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries)
1114+
```
1115+
11071116
<!-- marker-proxy-end -->
11081117

11091118
### Delete data

influxdb_client/client/flux_csv_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ def _prepare_data_frame(self):
251251

252252
# We have to create temporary DataFrame because we want to preserve default column values
253253
_temp_df = pd.DataFrame(self._data_frame_values)
254+
# This is for backward compatibles reason
255+
# In newer Pandas versions 'string' type will be 'str', in older versions 'string' type will be 'object'
256+
# In newer Pandas versions 'time' will be 'datetime64[us, UTC]', in older versions 'time'
257+
# will be 'datetime64[ns, UTC]'
258+
for column in _temp_df.columns:
259+
if _temp_df[column].dtype.name == 'str':
260+
_temp_df[column] = _temp_df[column].astype(object)
261+
if _temp_df[column].dtype.name == 'datetime64[us, UTC]':
262+
_temp_df[column] = _temp_df[column].astype('datetime64[ns, UTC]')
263+
254264
self._data_frame_values = []
255265

256266
# Custom DataFrame index

tests/test_WriteApi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,10 @@ def test_redirect(self):
532532
Retry.DEFAULT.remove_headers_on_redirect = Retry.DEFAULT_REMOVE_HEADERS_ON_REDIRECT
533533
self.influxdb_client.close()
534534

535-
self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org")
535+
# In the newer urllib3 versions >= 2.5.0 we need to set `redirect` and `remove_headers_on_redirect=[]` to
536+
# make it re-direct POST requests and stop it from remove the `Authorization` header.
537+
retries = Retry(redirect=1, remove_headers_on_redirect=[])
538+
self.influxdb_client = InfluxDBClient(url="http://localhost", token="my-token", org="my-org", retries=retries)
536539

537540
httpretty.register_uri(httpretty.POST, uri="http://localhost2/api/v2/write", status=204)
538541
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=301,

0 commit comments

Comments
 (0)