Install mitmproxy on Ubuntu 16.04 and Linux Mint 18

A simple tutorial to help install mitmproxy for debugging web applications on Linux Mint 18 / Ubuntu 16.04).

Install python 2.7 dev first (needed to avoid the error below):
$ sudo apt-get install python-dev

Now install mitmproxy
$ sudo pip install mitmproxy

Example usage with Ruby on Rails
Assuming we ran “rails server” on the default port of 3000, we can run mitmproxy on port 3001.
$ mitmproxy -p 3001 -R http://localhost:3000/

mitmproxy_request

mitmproxy_main

Error that would appear without installing python-dev:
creating build/temp.linux-x86_64-2.7/ext
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c ext/_yaml.c -o build/temp.linux-x86_64-2.7/ext/_yaml.o
ext/_yaml.c:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-t2Ejye/PyYAML/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-b7aU7h-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-t2Ejye/PyYAML/

Bookmark the permalink.