Skip to content

Commit dfa5ebc

Browse files
committed
add compat shim for urllib3 2.x
Signed-off-by: wwanarif <[email protected]>
1 parent 60921a0 commit dfa5ebc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

studio-backend/app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from app.compat import ensure_urllib3_getheaders
2+
3+
# Ensure urllib3 2.x exposes HTTPResponse.getheaders for kubernetes client compatibility.
4+
ensure_urllib3_getheaders()

studio-backend/app/compat.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Compatibility shims for third-party libraries.
3+
4+
Currently used to keep kubernetes-python working with urllib3 2.x, which
5+
removed HTTPResponse.getheaders(). Older kubernetes versions still call
6+
getheaders when building ApiException objects. This shim reintroduces a
7+
minimal getheaders that mirrors the previous behavior.
8+
"""
9+
from urllib3.response import HTTPResponse
10+
11+
12+
def ensure_urllib3_getheaders() -> None:
13+
"""Add HTTPResponse.getheaders if urllib3 2.x removed it.
14+
15+
Returns the header items as a list of (key, value) tuples, matching the
16+
old http.client.HTTPResponse API used by kubernetes-python.
17+
"""
18+
if not hasattr(HTTPResponse, "getheaders"):
19+
def _getheaders(self): # type: ignore[override]
20+
return list(self.headers.items())
21+
22+
HTTPResponse.getheaders = _getheaders # type: ignore[attr-defined]

studio-backend/app/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from fastapi import FastAPI
22
from fastapi.middleware.cors import CORSMiddleware
3+
4+
from app.compat import ensure_urllib3_getheaders
5+
6+
# Restore HTTPResponse.getheaders expected by kubernetes-python when running with urllib3 2.x.
7+
ensure_urllib3_getheaders()
8+
39
from kubernetes import config
410

511
# Load the kubeconfig file

0 commit comments

Comments
 (0)