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
FROM mitmproxy/mitmproxy:5.0.1
RUN pip install flask==1.1.1
COPY proxy.py proxy.py
CMD ["mitmdump", "-s", "proxy.py"]
docker build -t tpr .
docker run --network="host" --rm -it -v ~/.mitmproxy:/home/mitmproxy/.mitmproxy tpr
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?
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
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
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
loadfunction, we probably need to specify the addon top-level in the script. Does addingfix things for you?