From 51b8a980e6977abe9a4103f5b956c700c30336b1 Mon Sep 17 00:00:00 2001 From: Mia Miu Date: Sun, 2 Aug 2026 19:58:20 +1200 Subject: [PATCH] fix: avoid deprecated urllib3 header helpers --- tests/test_api_client/test_rest_response.py | 23 +++++++++++++++++++++ xero_python/rest.py | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/test_api_client/test_rest_response.py diff --git a/tests/test_api_client/test_rest_response.py b/tests/test_api_client/test_rest_response.py new file mode 100644 index 00000000..4dcacc2b --- /dev/null +++ b/tests/test_api_client/test_rest_response.py @@ -0,0 +1,23 @@ +from xero_python.rest import RESTResponse + + +class DummyResponse: + def __init__(self): + self.status = 200 + self.reason = "OK" + self.data = b"{}" + self.headers = { + "Content-Disposition": "attachment; filename=test.json", + "X-Trace-Id": "abc123", + } + + +def test_rest_response_reads_headers_without_deprecated_urllib3_helpers(): + response = RESTResponse(DummyResponse()) + + assert response.getheaders() == { + "Content-Disposition": "attachment; filename=test.json", + "X-Trace-Id": "abc123", + } + assert response.getheader("Content-Disposition") == "attachment; filename=test.json" + assert response.getheader("Missing", "fallback") == "fallback" diff --git a/xero_python/rest.py b/xero_python/rest.py index db0e84a6..7598deb0 100644 --- a/xero_python/rest.py +++ b/xero_python/rest.py @@ -45,11 +45,11 @@ def text(self): def getheaders(self): """Returns a dictionary of the response headers.""" - return self.urllib3_response.getheaders() + return dict(self.urllib3_response.headers.items()) def getheader(self, name, default=None): """Returns a given response header.""" - return self.urllib3_response.getheader(name, default) + return self.urllib3_response.headers.get(name, default) class RESTClientObject(object):