From 99bdd38f9f35746dfa288e79adc0516c04b07827 Mon Sep 17 00:00:00 2001 From: Ales Pour Date: Mon, 13 May 2024 12:46:10 +0200 Subject: [PATCH 1/4] fix: replace deprecated method calls --- influxdb_client/client/exceptions.py | 4 ++-- influxdb_client/rest.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/influxdb_client/client/exceptions.py b/influxdb_client/client/exceptions.py index 48681add..b62f4a75 100644 --- a/influxdb_client/client/exceptions.py +++ b/influxdb_client/client/exceptions.py @@ -15,7 +15,7 @@ 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') + self.retry_after = response.headers.get('Retry-After') else: self.response = None self.message = message or 'no response' @@ -34,7 +34,7 @@ def _get_message(self, response): # Header for header_key in ["X-Platform-Error-Code", "X-Influx-Error", "X-InfluxDb-Error"]: - header_value = response.getheader(header_key) + header_value = response.headers.get(header_key) if header_value is not None: return header_value diff --git a/influxdb_client/rest.py b/influxdb_client/rest.py index 8f50e51a..8f9c23c1 100644 --- a/influxdb_client/rest.py +++ b/influxdb_client/rest.py @@ -34,7 +34,7 @@ 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() + self.headers = http_resp.headers else: self.status = status self.reason = reason From f67b5f2c1e9a1e3b7a46f6b014f5e9c4516c9f1f Mon Sep 17 00:00:00 2001 From: Ales Pour Date: Mon, 13 May 2024 12:53:58 +0200 Subject: [PATCH 2/4] fix: internal RESTResponse have getheader() method --- influxdb_client/client/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb_client/client/exceptions.py b/influxdb_client/client/exceptions.py index b62f4a75..0c6b10b9 100644 --- a/influxdb_client/client/exceptions.py +++ b/influxdb_client/client/exceptions.py @@ -34,7 +34,7 @@ def _get_message(self, response): # Header for header_key in ["X-Platform-Error-Code", "X-Influx-Error", "X-InfluxDb-Error"]: - header_value = response.headers.get(header_key) + header_value = response.getheader(header_key) if header_value is not None: return header_value From 348f46ffc41e707701948ac6e269add7ef0d4b5e Mon Sep 17 00:00:00 2001 From: Ales Pour Date: Mon, 13 May 2024 15:32:23 +0200 Subject: [PATCH 3/4] fix: support initialization from both HTTPResponse and RESTResponse --- influxdb_client/client/exceptions.py | 5 ++++- influxdb_client/rest.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/influxdb_client/client/exceptions.py b/influxdb_client/client/exceptions.py index 0c6b10b9..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.headers.get('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 8f9c23c1..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.headers + 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 From 05e1bf2fcd36194b4876913222a72788d87aa6b3 Mon Sep 17 00:00:00 2001 From: Ales Pour Date: Mon, 13 May 2024 16:01:53 +0200 Subject: [PATCH 4/4] docs: update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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