Skip to content

Fix urllib3 getheaders/getheader deprecation in RESTResponse (#195)#225

Open
CedricConday wants to merge 1 commit into
XeroAPI:masterfrom
CedricConday:fix/195-urllib3-getheaders-deprecation
Open

Fix urllib3 getheaders/getheader deprecation in RESTResponse (#195)#225
CedricConday wants to merge 1 commit into
XeroAPI:masterfrom
CedricConday:fix/195-urllib3-getheaders-deprecation

Conversation

@CedricConday

@CedricConday CedricConday commented Jun 30, 2026

Copy link
Copy Markdown

Fixes #195

urllib3 deprecated HTTPResponse.getheaders() and HTTPResponse.getheader() in favour of accessing HTTPResponse.headers directly, and has scheduled them for removal. RESTResponse wrapped those deprecated accessors, so every response emitted a DeprecationWarning and the SDK would break once urllib3 drops them.

Change

RESTResponse now reads headers via .headers / .headers.get(name, default):

def getheaders(self):
    return self.urllib3_response.headers

def getheader(self, name, default=None):
    return self.urllib3_response.headers.get(name, default)

This is behaviour-preserving — in urllib3 2.x getheaders() returns self.headers and getheader(name, default) returns self.headers.get(name, default). The public RESTResponse.getheaders()/getheader() methods are unchanged, so the call sites in api_client/__init__.py and exceptions/__init__.py keep working.

Tests

Added tests/test_api_client/test_rest.py with version-independent regression tests: a spy response whose deprecated accessors raise if called, plus a check against a real urllib3 HTTPResponse. The spy tests fail on the old code and pass on the fix. Full test_api_client suite (150 tests) stays green.


AI-assisted, human-reviewed — I'm an AI engineer; I find, fix, and test with AI, then review and verify before opening.

…#195)

urllib3 deprecated HTTPResponse.getheaders() and getheader() in favour of
accessing HTTPResponse.headers directly. RESTResponse wrapped those
deprecated accessors, emitting DeprecationWarnings on every response and
risking breakage when urllib3 removes them.

Read headers via .headers / .headers.get() instead. The public
RESTResponse.getheaders()/getheader() methods are unchanged, so callers
in api_client and exceptions keep working. Adds regression tests pinning
the wrapper to the non-deprecated accessors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeprecationWarning in api_client and rest: getheader and getheaders

1 participant