{"id":10330,"library":"urllib3-mock","title":"urllib3-mock","description":"A utility library for mocking out the `urllib3` Python library. It allows intercepting HTTP requests made by `urllib3` and returning predefined responses for testing or development. The current version is 0.3.3, and the library appears to be abandoned, with no updates since 2017.","status":"abandoned","version":"0.3.3","language":"python","source_language":"en","source_url":"https://github.com/florentx/urllib3-mock","tags":["mocking","testing","http","urllib3","abandoned"],"install":[{"cmd":"pip install urllib3-mock","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for the library to be functional, as its entire purpose is to mock `urllib3` requests. Although not a strict `install_requires` dependency, it is essential for practical use.","package":"urllib3","optional":false}],"imports":[{"symbol":"Responses","correct":"from urllib3_mock import Responses"}],"quickstart":{"code":"from urllib3_mock import Responses\nimport urllib3\n\n# Create an instance of Responses\nresponses = Responses()\n\n@responses.add('GET', 'http://example.com/', body='hello world')\ndef test_mocked_request():\n    \"\"\"This function contains the urllib3 call that will be mocked.\"\"\"\n    http = urllib3.PoolManager()\n    r = http.request('GET', 'http://example.com/')\n    print(f\"Received: {r.data.decode('utf-8')}\")\n    assert r.data == b'hello world'\n\n# It's crucial to call the decorated function to execute the mocked request\ntest_mocked_request()\n","lang":"python","description":"This example demonstrates how to use `urllib3-mock` with a decorator to intercept a GET request to `http://example.com/` and return a custom body. It highlights the necessity of explicitly calling the decorated function for the mock to activate and the request to be intercepted."},"warnings":[{"fix":"For actively maintained mocking libraries for HTTP requests, consider `responses` (which targets `requests` and `urllib3`) or `pytest-mock` for more general mocking capabilities within a testing framework.","message":"The `urllib3-mock` library is no longer actively maintained, with the last commit and release (v0.3.3) dating back to 2017. Users should be aware of potential compatibility issues with newer Python versions or `urllib3` versions.","severity":"deprecated","affected_versions":"0.x"},{"fix":"If your primary library for HTTP requests is `requests`, consider using `responses` (https://github.com/getsentry/responses) which is designed to mock `requests` directly and is actively maintained.","message":"This library specifically hooks into `urllib3` directly. While `requests` uses `urllib3` internally, `urllib3-mock` might not always intercept requests made via the `requests` library in the way you expect, especially with more complex `requests` features.","severity":"gotcha","affected_versions":"0.x"},{"fix":"Always ensure the function decorated with `@responses.add` or `@responses.activate` is invoked. Alternatively, use `responses.start()` and `responses.stop()` as a context manager (`with responses:`) or manually around the `urllib3` call.","message":"When using decorators (e.g., `@responses.add`), the decorated function *must* be explicitly called for the mock to become active and intercept requests. If the function is not called, the `urllib3` request will go to the actual network.","severity":"gotcha","affected_versions":"0.x"}],"env_vars":null,"search_vec":"'0.3.3':34 '2017':46 'abandon':41,51 'allow':15 'appear':38 'current':31 'develop':29 'http':17,49 'intercept':16 'librari':6,13,37 'made':19 'mock':3,8,47 'predefin':24 'python':12 'request':18 'respons':25 'return':23 'sinc':45 'test':27,48 'updat':44 'urllib3':2,11,21,50 'urllib3-mock':1 'util':5 'version':32","created_at":"2026-04-17T01:23:34.482083+00:00","updated_at":"2026-04-17T01:23:34.482083+00:00","problems":[{"fix":"Verify that the URL, HTTP method (GET, POST, PUT, etc.), and any required headers in your `@responses.add` configuration exactly match the outgoing `urllib3` request. Also, ensure the mock context is active (either via a called decorator or `responses.start()/stop()`).","cause":"The `urllib3` request was not intercepted by `urllib3-mock` because no matching mock response was active or configured for the specific URL and HTTP method.","error":"urllib3.exceptions.MaxRetryError: HTTPConnectionPool(...) Max retries exceeded with url: ... (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ...>: Failed to establish a new connection: [Errno 111] Connection refused'))"},{"fix":"If using decorators, ensure the decorated function is explicitly called. If using `responses.start()`/`responses.stop()`, verify that the `urllib3` request is made between these calls or within a `with responses:` block.","cause":"The test or application code making the `urllib3` request did not execute within the active scope of the `urllib3-mock` `Responses` instance.","error":"AssertionError: Expected the request to be mocked, but it went to the network."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.3.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/florentx/urllib3-mock","docs":null,"changelog":null,"pypi":"https://pypi.org/project/urllib3-mock/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}