Registry / http-networking / mitmproxy

mitmproxy

JSON →
library12.2.3pypypi✓ verified 25d ago

Mitmproxy is an interactive, SSL/TLS-capable intercepting proxy for HTTP/1, HTTP/2, and WebSockets. It allows developers and security researchers to inspect, modify, and replay network traffic. Currently at version 12.2.1, it receives frequent patch and minor updates, with major versions introducing significant breaking changes less often.

pip install mitmproxy
INSTALL
IMPORT
SIG · MITMPROXY
M
mitmproxy
http-networkingpythonv12.2.3
Install
7.7s avg
Import
674ms
Disk
112MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v11.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.7s · import 0.674s · 120MB
112MB installed
● package 112MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTPFlow
from mitmproxy import http
from mitmproxy.flow import HTTPFlow
HTTPFlow is now typically accessed via `mitmproxy.http` namespace and often type-hinted directly from there.
Options
from mitmproxy import options
from mitmproxy.proxy import options
Global options are directly under the `mitmproxy` namespace via `mitmproxy.options`.
ctx
from mitmproxy import ctx
The context object (`mitmproxy.ctx`) provides access to global state, logging, and master instance.
Addon
from mitmproxy.addonmanager import Addon
Base class for type hinting or extending mitmproxy addons, though often not explicitly inherited for simple callback-based addons.

This quickstart demonstrates a basic mitmproxy addon that intercepts and modifies HTTP requests and responses. It adds custom headers for traffic to 'example.com'. To run, save this code as a `.py` file (e.g., `myaddon.py`) and execute `mitmproxy -s myaddon.py` in your terminal, then configure your client to use mitmproxy as a proxy.

import os from mitmproxy import http class SimpleModifier: def request(self, flow: http.HTTPFlow): # Modify all requests to example.com if "example.com" in flow.request.pretty_url: flow.request.headers["X-Modified-By"] = "Mitmproxy-Addon" # To redirect, uncomment and adjust: # flow.request.host = "www.google.com" # flow.request.port = 443 # flow.request.scheme = "https" # Access options via flow.options or mitmproxy.ctx.options # print(f"Verbosity: {flow.options.verbosity}") def response(self, flow: http.HTTPFlow): # Modify all responses from example.com if flow.response and "example.com" in flow.request.pretty_url: flow.response.headers["X-Response-Modified-By"] = "Mitmproxy-Addon" # Modify response content (ensure it's bytes) # if flow.response.content: # flow.response.content = flow.response.content.replace(b"example", b"modified") # To run this addon: # 1. Save it as e.g., `myaddon.py` # 2. Run mitmproxy from your terminal: `mitmproxy -s myaddon.py` # 3. Configure your client (browser, app) to proxy through mitmproxy (default: http://127.0.0.1:8080). # For HTTPS, install the mitmproxy CA certificate (navigate to mitm.it from the proxied client).
mitmproxy --version
Debug
Known issues
breakingMitmproxy v12.0.0 and later require Python 3.12+. Earlier versions required Python 3.11+ (v9.0.0+) or Python 3.8+ (prior to v9.0.0).
fix
Ensure your Python environment meets the minimum requirement for your mitmproxy version. Upgrade to Python 3.12 or higher for mitmproxy 12+.
affects: >=12.0.0
breakingThe `flow.request.url` and `flow.response.url` attributes were removed in v9.0.0. Use `flow.request.pretty_url` for display or reconstruct the URL. Similarly, direct access to `flow.request.host` and `flow.request.port` was deprecated.
fix
Replace `flow.request.url` with `flow.request.pretty_url` (for a user-friendly string) or reconstruct from `flow.request.scheme`, `flow.request.host`, `flow.request.port`, and `flow.request.path`. Use `flow.request.pretty_host` for the host name.
affects: >=9.0.0
breakingContent attributes (`request.content`, `response.content`) now always return `bytes` or `None` since v6.0.0. Direct assignment of `str` or non-bytes objects will raise an error.
fix
Ensure you are working with `bytes` for `content`. If you need string representation, explicitly decode (e.g., `flow.response.content.decode('utf-8')`) and encode back before setting (e.g., `b'new content'`).
affects: >=6.0.0
gotchaAddon methods (like `request`, `response`) must be synchronous. Directly using `async def` will not work. If you need asynchronous operations, use `asyncio.run()` or similar within a synchronous method.
fix
Rewrite asynchronous logic to be called synchronously, typically by wrapping `await` calls with `asyncio.run()` or using `loop.run_until_complete()` within your synchronous addon method, or run `asyncio.run()` in the main thread outside the addon.
affects: all
gotchaClients must explicitly trust the mitmproxy CA certificate to avoid SSL/TLS errors. This is a common setup oversight, leading to `SSL_ERROR_HANDSHAKE_FAILURE` or similar.
fix
After starting mitmproxy, configure your client to proxy through it, then navigate to `http://mitm.it` through that client to download and install the CA certificate. Refer to the mitmproxy documentation for detailed installation instructions for your specific client/OS.
affects: all
breakingInstalling `mitmproxy` on Alpine Linux may fail during the build of its Rust-based dependency (`mitmproxy-rs`) due to missing system libraries or build tools (e.g., `libgcc_s.so.1`). This can manifest as `Error loading shared library` or `subprocess.CalledProcessError` with exit status 127.
fix
On Alpine Linux, ensure `libgcc` and `build-base` packages are installed via `apk add libgcc build-base` before attempting to install `mitmproxy`. Alternatively, consider using a less minimal base image (e.g., Debian or Ubuntu) which typically includes these dependencies by default or has easier setup for Rust compilation.
affects: all
Errors
Common errors & fixes
mitmproxy certificate verify failed: unable to get local issuer certificate
The client device (browser, mobile app) does not trust the SSL/TLS certificate authority (CA) generated by mitmproxy, leading to TLS handshake failures.
fix
Install the mitmproxy CA certificate on the client device. This is typically done by configuring the client to use mitmproxy as a proxy, then navigating to `http://mitm.it` and following the installation instructions for your specific OS/device. Alternatively, manually import `~/.mitmproxy/mitmproxy-ca-cert.pem` (or `.p12` for Windows) into your system's trust store.
Error connecting to "127.0.0.1": [Errno 61] Connection refused
The client attempted to connect to mitmproxy, but mitmproxy was either not running, not listening on the specified address/port, or a firewall/network configuration blocked the connection.
fix
Ensure mitmproxy (e.g., `mitmproxy`, `mitmweb`, or `mitmdump`) is actively running and listening on the expected port (default 8080). Verify the client's proxy settings correctly point to mitmproxy's IP address and port. Check firewall rules on the mitmproxy host to allow incoming connections.
ModuleNotFoundError: No module named 'libmproxy'
This error often occurs when running custom mitmproxy scripts or addons with older mitmproxy versions or when a script uses deprecated import paths. The `libmproxy` namespace was refactored and removed in newer versions of mitmproxy.
fix
Update your mitmproxy installation to a recent version (if applicable) and modify your addon script to use the current import structure, typically `from mitmproxy import ...` instead of `from libmproxy import ...`. If the issue persists with other modules, ensure mitmproxy was installed via `pip` or `pipx` into your Python environment, and then `pip install` any additional required modules, as standalone binaries include their own Python environment.
If you can see this, traffic is not passing through mitmproxy.
This message appears when visiting `http://mitm.it` if the client device is not correctly configured to route its HTTP/HTTPS traffic through the running mitmproxy instance, or if there's a network issue preventing the client from reaching the proxy.
fix
Verify that your client's proxy settings are accurately configured to point to the IP address and port where mitmproxy is listening (e.g., `localhost:8080` for a local setup). Ensure there are no network connectivity issues or firewalls blocking communication between the client and mitmproxy. If using transparent mode, double-check your `iptables` or routing configurations.
Upgrade
Version history
12.2.3latest on PyPI · released May 12, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
42
OpenAI (training)
1
Resources
mitmproxy — pip install mitmproxy · libregistry