Setting second proxy for libmproxy


Hello, I’m trying to set up libmproxy (it’s easier to debug and it’s better for my purpose) with a second proxy server

initiation code looks like:

class StickyMaster(controller.Master):
def init(self, server):
controller.Master.init(self, server)
self.stickyhosts = {}

def run(self):
    except KeyboardInterrupt:

def handle_request(self, flow):
    if in_scope(flow):
        print flow.request.content
        print flow

    if FAIL_REPORT_URL not in flow.request.url:
        print "EVIL REQUEST"
        print flow

def handle_response(self, flow):

config = proxy.ProxyConfig(port=8084, mode=“upstream”, upstream_server=“”)
server = ProxyServer(config)
m = StickyMaster(server)

and I’m getting such error:

mitmproxy has crashed!
Please lodge a bug report at:
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/”, line 110, in handle
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/”, line 208, in establish_server_connection
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/”, line 148, in connect
File “/usr/lib/python2.7/dist-packages/netlib/”, line 538, in connect
File “/usr/lib/python2.7/”, line 224, in meth
return getattr(self._sock,name)(*args)
TypeError: getsockaddrarg() takes exactly 2 arguments (15 given)

Could you please explain how should i start libMProxy for using custom scripts with another proxy server?
Thanks for help.



It looks like you are using a very outdated version of mitmproxy. You should update! :slight_smile:


Thx, i’ve updated mitm proxy, had some problems with system.

Would be great if you could help me with these questions:

  1. I’ve tried to find in code methods where events callback from inline scripts (from this documentation are called), to import them and use, and i didn’t find.
    Could you please help me to do it? I mean something like import request from somewhere so it would be called on event.

  2. Could you please also advise what method to import to override proxy start and configure it from script, like stickyMaster from old version?

Thank you.


See here. To be clear, this is quite nontrivial Python code.

May I ask what’s your use case for this? We’re currently in the process of adding a better support for config files.


This is still krockssb, but i forgot account.

Thank you for answering first question, I’ll try it once more with a right place now.[quote=“mhils, post:4, topic:414”]
May I ask what’s your use case for this? We’re currently in the process of adding a better support for config files.

Main idea is to set few proxies with different separate tasks independent from each other, e.g. auth, traffic modifying, traffic analyse, etc. And also something like a burpsuite for easy viewing and work.

So i’m trying to find out how to work with to of these things (settings, and callbacks) from one place in code, so simplifying. For now, i couldn’t handled it.