-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
Summary
With urllib3>=2.6.0, the Brevo/SendinBlue Python client fails at runtime with:
AttributeError: 'HTTPResponse' object has no attribute 'getheaders'
This happens when ApiException is raised and the SDK calls http_resp.getheaders().
Evidence / references
- urllib3 2.6.0 removed
HTTPResponse.getheaders()/getheader()in favor ofHTTPResponse.headers/HTTPResponse.headers.get(...)(see release notes, removal #3622):
https://github.com/urllib3/urllib3/releases/tag/2.6.0 - urllib3 v2 migration guide also notes the deprecation & planned removal:
https://urllib3.readthedocs.io/en/2.5.0/v2-migration-guide.html - SDK currently calls
http_resp.getheaders()insib_api_v3_sdk/rest.py(and wraps urllib3 responses):
https://github.com/sendinblue/APIv3-python-library/blob/master/sib_api_v3_sdk/rest.py
Reproduction
pip install "sib-api-v3-sdk==7.6.0" "urllib3>=2.6.0"Trigger any API error (401/403/etc.) so the SDK raises ApiException, e.g. invalid API key:
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
cfg = sib_api_v3_sdk.Configuration()
cfg.api_key["api-key"] = "invalid"
api = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(cfg))
try:
api.get_smtp_templates()
except ApiException as e:
print("caught:", e)Proposed fix (backwards compatible)
Update the SDK response wrapper to use .headers when getheaders() / getheader() are not available:
# sib_api_v3_sdk/rest.py
def getheaders(self):
if hasattr(self.urllib3_response, "getheaders"):
return self.urllib3_response.getheaders()
return self.urllib3_response.headers
def getheader(self, name, default=None):
if hasattr(self.urllib3_response, "getheader"):
return self.urllib3_response.getheader(name, default)
return self.urllib3_response.headers.get(name, default)Workaround
Pin urllib3 until the SDK is regenerated/fixed:
urllib3<2.6
Metadata
Metadata
Assignees
Labels
No labels