{"id":10359,"library":"wsgiproxy2","title":"WSGIProxy2","description":"WSGIProxy2 is a Python library that provides a WSGI application to proxy HTTP requests to another server, supporting various HTTP client backends like requests, urllib3, or httpx. It allows for flexible routing and handling of incoming requests before forwarding them to a specified target URI. The current version is 0.5.1, and the project is maintained with infrequent but steady updates.","status":"active","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/gawel/WSGIProxy2/","tags":["wsgi","proxy","http","server","middleware"],"install":[{"cmd":"pip install wsgiproxy2","lang":"bash","label":"Basic installation"},{"cmd":"pip install wsgiproxy2[httpx]","lang":"bash","label":"Installation with httpx backend"}],"dependencies":[{"reason":"Required for basic functionality and commonly used with WSGI apps.","package":"werkzeug","optional":false},{"reason":"Default HTTP client backend, installed by default.","package":"requests","optional":false},{"reason":"Optional HTTP client backend, installed via `wsgiproxy2[urllib3]`.","package":"urllib3","optional":true},{"reason":"Optional HTTP client backend, installed via `wsgiproxy2[httpx]`.","package":"httpx","optional":true}],"imports":[{"note":"The package name is 'wsgiproxy2', but the main 'Proxy' class is imported from the 'wsgiproxy' module.","wrong":"from wsgiproxy2 import Proxy","symbol":"Proxy","correct":"from wsgiproxy import Proxy"}],"quickstart":{"code":"from wsgiproxy import Proxy\nfrom werkzeug.serving import run_simple\nimport os\n\n# Configure the target URI for the proxy\nTARGET_URI = os.environ.get('WSGIPROXY_TARGET_URI', 'http://localhost:8000')\n\n# Create a Proxy instance, mapping '/proxy-path' to TARGET_URI\n# All requests to '/proxy-path' will be forwarded to TARGET_URI\napplication = Proxy(\n    '/proxy-path',\n    TARGET_URI\n)\n\nif __name__ == '__main__':\n    print(f\"Proxying requests from http://localhost:5000/proxy-path to {TARGET_URI}\")\n    # Run the WSGI application using Werkzeug's development server\n    run_simple('localhost', 5000, application)\n","lang":"python","description":"This quickstart demonstrates how to set up a basic WSGI proxy using `wsgiproxy2` with `werkzeug.serving`. It creates a proxy application that forwards requests from '/proxy-path' on the local server to a specified target URI. Ensure your target server is running or set `WSGIPROXY_TARGET_URI` environment variable to a valid URL."},"warnings":[{"fix":"Always import the `Proxy` class using `from wsgiproxy import Proxy`.","message":"The package is installed as `wsgiproxy2` but the primary class `Proxy` is imported from the `wsgiproxy` module. Using `from wsgiproxy2 import Proxy` will result in a `ModuleNotFoundError` or `AttributeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Specify the desired backend during installation: `pip install wsgiproxy2[urllib3]` or `pip install wsgiproxy2[httpx]`.","message":"While `requests` is installed by default as the backend, to use `urllib3` or `httpx`, you must install `wsgiproxy2` with the corresponding extra dependencies (e.g., `pip install wsgiproxy2[httpx]`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Wrap the `Proxy` application with custom WSGI middleware to catch specific HTTP status codes or exceptions and handle them gracefully (e.g., return a custom error page, log, or retry).","message":"By default, `wsgiproxy2` will propagate backend errors (e.g., connection refused, 404 from target) as the proxy's response. For more robust applications, you may need to implement custom error handling or retry logic using middleware.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change the import statement to `from wsgiproxy import Proxy`.","cause":"Attempting to import `Proxy` directly from the `wsgiproxy2` package name, instead of the correct `wsgiproxy` module name.","error":"ModuleNotFoundError: No module named 'wsgiproxy2'"},{"fix":"Ensure you pass both the `local_path` and `target_uri` when instantiating the `Proxy` object, e.g., `application = Proxy('/my-path', 'http://example.com/api')`.","cause":"The `Proxy` class constructor requires at least two arguments: the local path to proxy, and the target URI.","error":"TypeError: __init__() missing 1 required positional argument: 'target_uri'"},{"fix":"Verify that the `target_uri` is correct and that the backend server it points to is actively running and accessible from where the `wsgiproxy2` application is hosted.","cause":"The `target_uri` specified for the proxy is unreachable, or the backend server is not running/listening on the specified address and port.","error":"requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ...>: Failed to establish a new connection: [Errno 111] Connection refused'))"}]}