{"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":"en","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,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","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."}]}