Mitmproxy: Can't get the WSGI example to work

Created on 17 Jan 2020  路  4Comments  路  Source: mitmproxy/mitmproxy

Problem Description

I was running code very similar to that in the wsgi_flask_app.py example in my project, hoping to serve a basic flask app under a test domain when the proxy is running. Couldn't get it working in my project so after some experimenting I tried to repro the simple example, using mitmproxy 5.0.1 docker image as a base, but I'm still having trouble.
Basically mitmdump doesn't seem to be able to resolve the magic "proxapp.local" domain - when I make requests to it on port 80, the mitmdump logs the request but says:

GET http://proxapp.local/
<< Server connection to ('proxapp.local', 80) failed: Error connecting to "proxapp.local": [Errno -2] Name does not resolve

Steps to reproduce the behavior:

  1. This is my Dockerfile
FROM mitmproxy/mitmproxy:5.0.1

RUN pip install flask==1.1.1

COPY proxy.py proxy.py

CMD ["mitmdump", "-s", "proxy.py"]
  1. The contents of proxy.py is just copy pasted from: https://github.com/mitmproxy/mitmproxy/blob/v5.0.1/examples/simple/wsgi_flask_app.py
  2. I'm running it with:
docker build -t tpr .
docker run --network="host" --rm -it -v ~/.mitmproxy:/home/mitmproxy/.mitmproxy tpr
  1. Making requests via the browser (set up to proxy via localhost:8080) to http://proxapp.local gives a 502

My understanding was that I should get back the test "Hello World!" response. Have I missed something?

Also, at some point during my experimentation I uncommented the line at the bottom of the example :
mitmproxy.ctx.master.apps.add(app, "example.com", 443)
but got some error about how apps is not defined on ctx.master, is that information still applicable to v5.0.1?

System Information

Paste the output of "mitmproxy --version" here.
(Running from a shell inside the running container):

Mitmproxy: 5.0.1
Python:    3.6.9
OpenSSL:   OpenSSL 1.0.2u  20 Dec 2019
Platform:  Linux-4.15.0-72-generic-x86_64-with
areexamples kinbug

Most helpful comment

Thanks for the super detailed repro instructions (which make us look at things right away)! 鉂わ笍

It looks like our example is indeed broken. Instead of using the load function, we probably need to specify the addon top-level in the script. Does adding

addons = [
    wsgiapp.WSGIApp(app, "proxapp.local", 80)
]

fix things for you?

All 4 comments

Thanks for the super detailed repro instructions (which make us look at things right away)! 鉂わ笍

It looks like our example is indeed broken. Instead of using the load function, we probably need to specify the addon top-level in the script. Does adding

addons = [
    wsgiapp.WSGIApp(app, "proxapp.local", 80)
]

fix things for you?

Indeed it does - thank you so much for the speedy response! :)

Thanks! You did the majority of the work here, do you want to open a pull request that fixes the example? 馃槂

I can't get the SSL version of the app to work.
When I uncomment this line.
# mitmproxy.ctx.master.apps.add(app, "example.com", 443)
I get this error:
in script simple\wsgi_flask_app.py:41 invalid syntax (wsgi_flask_app.py, line 41)

System Information

Mitmproxy: 5.1.1 binary
Python:    3.7.6
OpenSSL:   OpenSSL 1.1.1f  31 Mar 2020
Platform:  Windows-10-10.0.18362-SP0
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mancubus77 picture mancubus77  路  3Comments

prastut picture prastut  路  5Comments

mhils picture mhils  路  4Comments

adforcetestuser1 picture adforcetestuser1  路  5Comments

zero-master picture zero-master  路  3Comments