Skip to content

Commit 5e141ec

Browse files
Address urllib3 incompatibility in unified_http_client.py
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent af362b8 commit 5e141ec

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/databricks/sql/common/unified_http_client.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
from urllib3.util import make_headers
1111
from urllib3.exceptions import MaxRetryError
1212

13+
# Compatibility import for different urllib3 versions
14+
try:
15+
# If urllib3~=2.0 is installed
16+
from urllib3 import BaseHTTPResponse
17+
except ImportError:
18+
# If urllib3~=1.0 is installed
19+
from urllib3 import HTTPResponse as BaseHTTPResponse
20+
1321
from databricks.sql.auth.retry import DatabricksRetryPolicy, CommandType
1422
from databricks.sql.exc import RequestError
1523
from databricks.sql.common.http import HttpMethod
@@ -222,7 +230,7 @@ def request_context(
222230
url: str,
223231
headers: Optional[Dict[str, str]] = None,
224232
**kwargs,
225-
) -> Generator[urllib3.BaseHTTPResponse, None, None]:
233+
) -> Generator[BaseHTTPResponse, None, None]:
226234
"""
227235
Context manager for making HTTP requests with proper resource cleanup.
228236
@@ -233,7 +241,7 @@ def request_context(
233241
**kwargs: Additional arguments passed to urllib3 request
234242
235243
Yields:
236-
urllib3.BaseHTTPResponse: The HTTP response object
244+
BaseHTTPResponse: The HTTP response object
237245
"""
238246
logger.debug(
239247
"Making %s request to %s", method, urllib.parse.urlparse(url).netloc
@@ -270,7 +278,7 @@ def request(
270278
url: str,
271279
headers: Optional[Dict[str, str]] = None,
272280
**kwargs,
273-
) -> urllib3.BaseHTTPResponse:
281+
) -> BaseHTTPResponse:
274282
"""
275283
Make an HTTP request.
276284
@@ -281,7 +289,7 @@ def request(
281289
**kwargs: Additional arguments passed to urllib3 request
282290
283291
Returns:
284-
urllib3.BaseHTTPResponse: The HTTP response object with data and metadata pre-loaded
292+
BaseHTTPResponse: The HTTP response object with data and metadata pre-loaded
285293
"""
286294
with self.request_context(method, url, headers=headers, **kwargs) as response:
287295
# Read the response data to ensure it's available after context exit

0 commit comments

Comments
 (0)