The way to start mitmproxy from python script #5255
Replies: 4 comments 10 replies
-
from mitmproxy.tools.main import mitmdump
mitmdump(args=["-s", "myaddon.py"]) |
Beta Was this translation helpful? Give feedback.
-
I am using a script like this to run the proxy: #!/bin/env python
import asyncio
import sys
from mitmproxy import options
from mitmproxy.tools import dump
class RequestLogger:
def request(self, flow):
print(flow.request)
async def start_proxy(host, port):
opts = options.Options(listen_host=host, listen_port=port)
master = dump.DumpMaster(
opts,
with_termlog=False,
with_dumper=False,
)
master.addons.add(RequestLogger())
await master.run()
return master
if __name__ == '__main__':
host=sys.argv[1]
port=int(sys.argv[2])
asyncio.run(start_proxy(host, port)) The only tricky part for me was to install mitmproxy in my virtual env from the sources: git clone https://github.com/mitmproxy/mitmproxy.git
cd mitmproxy
pip install . Also my python version is |
Beta Was this translation helpful? Give feedback.
-
Anyone know how to get this: to run only like this: |
Beta Was this translation helpful? Give feedback.
-
in cmd,I can
|
Beta Was this translation helpful? Give feedback.
-
Hello!
I am looking for a possibility to start proxy from a python - need to work with requests in my automated tests
I've found solution in #3306 branch, but it seems that something has changed - script like below can't start in case of AttributeError
So is there an alternate solution?
mitmproxy 8.0.0
Thanks for any responses!
Beta Was this translation helpful? Give feedback.
All reactions