urllib3 is a powerful, user-friendly HTTP client library for Python providing thread-safe connection pooling, client-side TLS/SSL verification, multipart file uploads, retry helpers, redirect handling, and support for gzip, deflate, brotli, and zstd content encoding. Current stable version is 2.6.3 (released 2025). The project follows an active release cadence with security patches, minor feature releases, and occasional major versions; the 2.x line requires Python >=3.9 and OpenSSL >=1.1.1.
pip install urllib3Verified import paths — ran on the pinned version, not inferred.
Create an explicit PoolManager and make GET/POST requests with timeout and retry logic.
Upgrade the Python runtime (Lambda: use Python 3.10+), or pin urllib3<2 if the runtime cannot be changed.
Import VerifiedHTTPSConnection from urllib3.connection; remove all references to DEFAULT_CIPHERS (urllib3 now uses the system cipher list).
Replace ssl_version=ssl.PROTOCOL_TLSv1_2 with ssl_minimum_version=ssl.TLSVersion.TLSv1_2 when constructing an SSLContext or calling create_urllib3_context().
Reissue certificates with a proper subjectAltName extension, or set cert_reqs='CERT_NONE' only for internal/test environments (never production).
Instantiate an explicit urllib3.PoolManager() and keep it as a long-lived object; pass it around rather than relying on the global shortcut.
Pass preload_content=False to request(), then iterate with resp.stream(chunk_size) and always call resp.release_conn() when done.
Upgrade to urllib3>=2.6.3 immediately.
Increase the number of retries or adjust the timeout settings for your PoolManager, and ensure the target server is accessible and responsive.
```python
import urllib3
http = urllib3.PoolManager(
retries=urllib3.Retry(total=5, backoff_factor=0.5, status_forcelist=[500, 502, 503, 504]),
timeout=urllib3.Timeout(connect=2.0, read=5.0)
)
try:
r = http.request('GET', 'http://example.com/resource', retries=3)
print(r.status)
except urllib3.exceptions.MaxRetryError as e:
print(f"Request failed after max retries: {e}")
```Ensure `certifi` is installed and up-to-date (`pip install --upgrade certifi`), and your `PoolManager` is configured to use it, or provide a custom CA bundle if necessary.
```python
import urllib3
import certifi
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where() # Ensures the latest CA certificates are used
)
try:
r = http.request('GET', 'https://secure.example.com')
print(r.status)
except urllib3.exceptions.SSLError as e:
print(f"SSL Certificate Error: {e}")
```Verify that the target host and port are correct, the server is running and accessible, and there are no network or firewall restrictions blocking the connection.
```python
import urllib3
import socket
http = urllib3.PoolManager()
try:
r = http.request('GET', 'http://invalid-host-or-port.com:9999') # Correct this URL
print(r.status)
except (urllib3.exceptions.NewConnectionError, socket.gaierror) as e:
print(f"Connection establishment failed: {e}")
print("Please check the hostname, port, server status, and network connectivity.")
```Install the `urllib3` library using pip in your active Python environment. ```bash pip install urllib3 ```