diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4465cb..9391f964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 1.43.0 [unreleased] +### Bug Fixes +1. [#655](https://github.com/influxdata/influxdb-client-python/pull/655): Replace deprecated `urllib` calls `HTTPResponse.getheaders()` and `HTTPResponse.getheader()`. + ## 1.42.0 [2024-04-17] ### Bug Fixes diff --git a/influxdb_client/client/exceptions.py b/influxdb_client/client/exceptions.py index 48681add..2ca235c8 100644 --- a/influxdb_client/client/exceptions.py +++ b/influxdb_client/client/exceptions.py @@ -15,7 +15,10 @@ def __init__(self, response: HTTPResponse = None, message: str = None): if response is not None: self.response = response self.message = self._get_message(response) - self.retry_after = response.getheader('Retry-After') + if isinstance(response, HTTPResponse): # response is HTTPResponse + self.retry_after = response.headers.get('Retry-After') + else: # response is RESTResponse + self.retry_after = response.getheader('Retry-After') else: self.response = None self.message = message or 'no response' diff --git a/influxdb_client/rest.py b/influxdb_client/rest.py index 8f50e51a..cd4dbff4 100644 --- a/influxdb_client/rest.py +++ b/influxdb_client/rest.py @@ -13,7 +13,7 @@ import logging from typing import Dict - +from urllib3 import HTTPResponse from influxdb_client.client.exceptions import InfluxDBError from influxdb_client.configuration import Configuration @@ -34,7 +34,10 @@ def __init__(self, status=None, reason=None, http_resp=None): self.status = http_resp.status self.reason = http_resp.reason self.body = http_resp.data - self.headers = http_resp.getheaders() + if isinstance(http_resp, HTTPResponse): # response is HTTPResponse + self.headers = http_resp.headers + else: # response is RESTResponse + self.headers = http_resp.getheaders() else: self.status = status self.reason = reason