{"id":4236,"library":"requestsexceptions","title":"Requests Exceptions","description":"requestsexceptions is a simple utility library designed to normalize the import paths for exceptions within the popular 'requests' HTTP library. It addresses scenarios where 'requests' might bundle 'urllib3' or be distributed with 'urllib3' unbundled, which can lead to inconsistencies when trying to catch specific exceptions like `urllib3.exceptions.HTTPError`. The library provides a unified way to import these exceptions, regardless of the underlying 'requests' packaging. Its current version is 1.4.0, released in February 2018, indicating a maintenance-focused cadence.","status":"maintenance","version":"1.4.0","language":"en","source_language":"en","source_url":"https://opendev.org/openstack/requestsexceptions","tags":["requests","exceptions","error-handling","urllib3","network"],"install":[{"cmd":"pip install requestsexceptions","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This library is designed to work with the 'requests' library's exceptions. 'requests' is a de-facto dependency for its usage.","package":"requests","optional":false}],"imports":[{"symbol":"ConnectionError","correct":"from requestsexceptions import ConnectionError"},{"symbol":"HTTPError","correct":"from requestsexceptions import HTTPError"},{"symbol":"Timeout","correct":"from requestsexceptions import Timeout"},{"note":"While directly importing from `requests.exceptions` is standard for `requests` itself, `requestsexceptions` aims to abstract away potential inconsistencies in `requests`' exception bundling, making its import path the intended 'correct' one when using this library.","wrong":"from requests.exceptions import RequestException","symbol":"RequestException","correct":"from requestsexceptions import RequestException"}],"quickstart":{"code":"import requests\nfrom requestsexceptions import ConnectionError, Timeout, HTTPError, RequestException\n\ndef fetch_url(url):\n    try:\n        response = requests.get(url, timeout=1)\n        response.raise_for_status() # Raises HTTPError for bad responses (4xx or 5xx)\n        print(f\"Successfully fetched {url}, status: {response.status_code}\")\n    except ConnectionError:\n        print(f\"Connection error occurred for {url}.\")\n    except Timeout:\n        print(f\"Request timed out for {url}.\")\n    except HTTPError as e:\n        print(f\"HTTP error for {url}: {e.response.status_code}\")\n    except RequestException as e:\n        print(f\"An unexpected Requests error occurred for {url}: {e}\")\n    except Exception as e:\n        print(f\"An non-Requests error occurred for {url}: {e}\")\n\nfetch_url('https://httpbin.org/status/200')\nfetch_url('https://httpbin.org/status/404')\nfetch_url('http://nonexistent.domain.xyz')\nfetch_url('https://httpbin.org/delay/5')","lang":"python","description":"This quickstart demonstrates how to use `requestsexceptions` to catch various network and HTTP-related errors when making requests using the 'requests' library. It covers `ConnectionError`, `Timeout`, `HTTPError`, and the general `RequestException`."},"warnings":[{"fix":"For new projects or when using modern `requests` versions (2.27.0+), it is generally recommended to directly import exceptions from `requests.exceptions` (e.g., `from requests.exceptions import ConnectionError`), as `requests`' own exception module is now quite stable. Evaluate if `requestsexceptions` is truly necessary for your specific `requests` version and environment.","message":"The `requestsexceptions` library was last updated in February 2018 (version 1.4.0). The 'requests' library has undergone significant development since then, including standardizing its internal exception handling (e.g., `requests.exceptions.JSONDecodeError` was introduced in `requests` 2.27.0).","severity":"deprecated","affected_versions":"All versions of `requestsexceptions` (1.x)"},{"fix":"Before integrating `requestsexceptions`, test direct imports from `requests.exceptions` in your target environment. If `requests.exceptions.ConnectionError` (and other specific exceptions you need) resolves correctly and behaves as expected, `requestsexceptions` might be an unnecessary dependency.","message":"The primary problem `requestsexceptions` solves is the potential inconsistency in exception paths due to 'requests' bundling/unbundling `urllib3`. For many common use cases, especially with recent and stable 'requests' installations, directly importing from `requests.exceptions` is robust enough and may not require this extra abstraction.","severity":"gotcha","affected_versions":"All versions of `requestsexceptions` (1.x)"},{"fix":"Consider the potential risks of relying on an unmaintained library. For critical applications, prefer the native `requests.exceptions` or a more actively maintained solution if `requests.exceptions` proves insufficient in very specific, legacy, or highly customized environments.","message":"The library's long-term maintenance status is unclear, with its official GitHub being a mirror of opendev.org. No recent commits or releases indicate active development to keep pace with 'requests' library changes.","severity":"gotcha","affected_versions":"All versions of `requestsexceptions` (1.x)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}