{"id":206,"library":"requests","title":"Requests","description":"The de facto standard synchronous HTTP client for Python. Current version is 2.32.5 (Aug 2025). Stable, slow-moving library. Primary footgun: no default timeout — hangs forever by default. No async support — use httpx or aiohttp for async contexts.","status":"active","version":"2.32.5","language":"python","source_language":"en","source_url":"https://github.com/psf/requests/blob/main/HISTORY.md","tags":["http","client","networking","sync","web-scraping"],"install":[{"cmd":"pip install requests","lang":"bash","label":"Core"}],"dependencies":[{"reason":"HTTP connection pooling. Installed automatically. urllib3 2.x requires OpenSSL 1.1.1+.","package":"urllib3>=1.21.1,<3","optional":false},{"reason":"CA certificate bundle. Installed automatically.","package":"certifi>=2017.4.17","optional":false},{"reason":"Character encoding detection. Installed automatically.","package":"charset-normalizer>=2,<4","optional":false},{"reason":"Internationalized domain names. Installed automatically.","package":"idna<4,>=2.5","optional":false}],"imports":[{"note":"requests has NO default timeout. Omitting timeout= causes the request to block indefinitely on slow or unresponsive servers. This is the single most common production issue with requests.","wrong":"import requests\nresponse = requests.get('https://example.com')  # no timeout — hangs forever on unresponsive hosts","symbol":"requests","correct":"import requests\n\n# Always set a timeout\nresponse = requests.get('https://example.com', timeout=30)"},{"note":"Use Session as a context manager to ensure connection pool cleanup. Session objects reuse connections automatically — always prefer Session over repeated requests.get() calls.","wrong":"session = requests.Session()\nresponse = session.get('https://example.com')\n# session never closed — connection pool leak","symbol":"Session","correct":"with requests.Session() as session:\n    response = session.get('https://example.com', timeout=30)"}],"quickstart":{"code":"import requests\n\n# One-shot (no connection reuse)\nresponse = requests.get('https://httpbin.org/get', timeout=30)\nresponse.raise_for_status()\ndata = response.json()\n\n# Session (connection reuse, recommended)\nwith requests.Session() as session:\n    session.headers.update({'Authorization': 'Bearer token'})\n    r = session.get('https://api.example.com/users', timeout=30)\n    r.raise_for_status()\n    users = r.json()","lang":"python","description":"Always pass timeout=. Use Session for multiple requests to same host."},"warnings":[{"fix":"Always pass timeout=(connect_timeout, read_timeout) or a single float: requests.get(url, timeout=30). For sessions: session.get(url, timeout=30).","message":"NO default timeout. requests.get(url) without timeout= hangs indefinitely if the server is slow or unresponsive. This is the #1 production incident cause in requests-based code. LLMs almost never include timeout in generated code.","severity":"breaking","affected_versions":"all"},{"fix":"Upgrade to requests>=2.32.3. Avoid verify=False in production entirely.","message":"verify=False on first request in a Session leaked to all subsequent requests to the same origin (security bug fixed in 2.32.3 / GHSA-9wx4-h78v-vm56). If using older versions, verify=False permanently disabled SSL for that origin in the session.","severity":"breaking","affected_versions":"< 2.32.3"},{"fix":"Override get_connection_with_tls_context(url, verify, cert, proxies) instead of _get_connection(). See requests 2.32.2 release notes for a minimal 2-line migration example.","message":"HTTPAdapter._get_connection() is deprecated since 2.32.0 following CVE-2024-35195. Custom HTTPAdapter subclasses that override _get_connection must migrate to get_connection_with_tls_context().","severity":"breaking","affected_versions":">= 2.32.0"},{"fix":"On affected systems, pin urllib3<2: pip install 'urllib3<2'. Or upgrade the OS/Python to one with OpenSSL 1.1.1+.","message":"urllib3 2.x requires OpenSSL 1.1.1+. On Amazon Linux 2, RHEL 7, or Python builds using older OpenSSL: ImportError: urllib3 v2 only supports OpenSSL 1.1.1+. Upgrading requests pulls in urllib3 2.x which breaks these environments.","severity":"breaking","affected_versions":"all (when urllib3>=2.0 installed)"},{"fix":"Use httpx.AsyncClient or aiohttp.ClientSession for async contexts. If you must use requests in async code, wrap in asyncio.to_thread(): await asyncio.to_thread(requests.get, url, timeout=30).","message":"requests has NO async support. Using requests in async code (asyncio, FastAPI, Starlette) blocks the entire event loop. requests.get() in an async def handler will freeze all concurrent requests.","severity":"gotcha","affected_versions":"all"},{"fix":"Use response.json() for JSON responses. Use response.content for binary. Use response.text only when you know the encoding or check response.encoding first.","message":"response.text uses charset detected from the response, which may be wrong. For JSON APIs, always use response.json() or response.content (bytes) rather than response.text to avoid encoding issues.","severity":"gotcha","affected_versions":"all"},{"fix":"Pass allow_redirects=False for sensitive POST requests. Check response.history to see if redirects occurred.","message":"redirect follows are enabled by default (allow_redirects=True). Requests will silently follow redirects, including redirecting POST to GET (HTTP 302 behavior). Sensitive POST data may be sent to an unexpected URL.","severity":"gotcha","affected_versions":"all"},{"fix":"First, inspect the server's logs for TLS handshake errors. Use `curl -vvv <your_url>` to get detailed information about the TLS negotiation (client/server supported versions, ciphers) and see if `curl` succeeds. Ensure no network proxies or firewalls are prematurely terminating the connection. As a diagnostic step, ensure `requests` and `urllib3` are updated to their latest versions to benefit from the most recent TLS capabilities.","message":"The TLS/SSL connection was unexpectedly closed by the peer (EOF) during or immediately after the handshake, leading to `SSLZeroReturnError`. This commonly indicates a server-side issue, an aggressive network intermediary, or a TLS version/cipher suite incompatibility where the server terminates the connection without a proper TLS alert. This is not typically a bug in requests/urllib3 itself, but an interaction problem.","severity":"breaking","affected_versions":"all"},{"fix":"Verify the target hostname is spelled correctly. Ensure the execution environment (container, VM, host machine) has proper DNS server configuration and network connectivity to resolve external domain names.","message":"DNS resolution failed. The hostname could not be resolved to an IP address (e.g., 'Name has no usable address' or 'Temporary failure in name resolution'). This typically indicates an environmental issue such as incorrect DNS server configuration, a firewall blocking DNS queries, or a typo in the hostname being requested.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T10:11:16.821Z","next_check":"2026-09-25T00:00:00.000Z","problems":[{"fix":"Always specify a `timeout` parameter (in seconds) in your `requests` calls to prevent indefinite hanging and handle the `Timeout` exception gracefully.","cause":"The request took longer than the specified `timeout` duration to receive a response from the server, or no timeout was specified causing the request to hang indefinitely.","error":"requests.exceptions.Timeout: Read timed out."},{"fix":"For trusted internal services or development, you can disable SSL verification with `verify=False` (use with caution for untrusted sites). For proper handling, ensure your system's CA certificates are up-to-date or provide a path to a custom certificate bundle using the `verify` parameter.","cause":"The `requests` library failed to verify the SSL/TLS certificate presented by the server, often due to self-signed certificates, an untrusted CA, or an outdated certificate authority bundle on the client system.","error":"requests.exceptions.SSLError: CERTIFICATE_VERIFY_FAILED"},{"fix":"Verify that the URL is correct, ensure the target server is running and accessible, check for any firewall restrictions, and confirm your network connectivity. Implement robust error handling for `ConnectionError`.","cause":"The `requests` library could not establish a connection to the target server, typically because the server is offline, the hostname or IP address is incorrect, or a network issue (like a firewall or DNS problem) is preventing access.","error":"requests.exceptions.ConnectionError: Max retries exceeded"},{"fix":"Correct the import statement by changing `import request` to `import requests`.","cause":"This error occurs when you attempt to import `request` (singular) instead of `requests` (plural), which is the correct name of the HTTP library.","error":"ModuleNotFoundError: No module named 'request'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":20,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.54,"mem_mb":9.6,"disk_size":"21.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.36,"mem_mb":9.6,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.72,"mem_mb":10.8,"disk_size":"23.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.58,"mem_mb":10.8,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.65,"mem_mb":11.2,"disk_size":"15.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.65,"mem_mb":11.2,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.64,"mem_mb":11.6,"disk_size":"14.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.61,"mem_mb":11.6,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.47,"mem_mb":9.4,"disk_size":"20.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.41,"mem_mb":9.4,"disk_size":"21M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":1}]}}