# Setting second proxy for libmproxy

**URL:** https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414
**Category:** help
**Created:** [March 13, 2017, 1:48pm UTC](https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414 "2017-03-13T13:48:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![krockssb](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@krockssb](https://discourse.mitmproxy.org/u/krockssb)
#### Post date: [March 13, 2017, 1:48pm UTC](https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414/1 "2017-03-13T13:48:55Z")

</div>

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):
    try:
        return controller.Master.run(self)
    except KeyboardInterrupt:
        self.shutdown()

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

    if FAIL_REPORT_URL not in flow.request.url:
        flow.reply()
    else:
        print "EVIL REQUEST"
        print flow

def handle_response(self, flow):
    in_scope(flow)
    flow.reply()

```

config = proxy.ProxyConfig(port=8084, mode=“upstream”, upstream\_server=“192.168.0.99:8085”)  
server = ProxyServer(config)  
m = StickyMaster(server)  
m.run()

and I’m getting such error:

mitmproxy has crashed!  
Please lodge a bug report at: [https://github.com/mitmproxy/mitmproxy](https://github.com/mitmproxy/mitmproxy)  
Traceback (most recent call last):  
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/server.py”, line 110, in handle  
self.establish\_server\_connection()  
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/server.py”, line 208, in establish\_server\_connection  
self.server\_conn.connect()  
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/connection.py”, line 148, in connect  
tcp.TCPClient.connect(self)  
File “/usr/lib/python2.7/dist-packages/netlib/tcp.py”, line 538, in connect  
connection.connect(self.address())  
File “/usr/lib/python2.7/socket.py”, 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.

---

<div class="post-metadata">

### Author: ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)
#### Post date: [March 13, 2017, 10:08pm UTC](https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414/2 "2017-03-13T22:08:22Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![krockssb](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@krockssb](https://discourse.mitmproxy.org/u/krockssb)
#### Post date: [April 2, 2017, 9:57pm UTC](https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414/3 "2017-04-02T21:57:42Z")

</div>

> [@mhils](#):
>
> e using a very outdated version of mitmproxy. You

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 [https://mitmproxy.org/doc/scripting/inlinescripts.html](https://mitmproxy.org/doc/scripting/inlinescripts.html) 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.

---

<div class="post-metadata">

### Author: ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)
#### Post date: [April 6, 2017, 1:02am UTC](https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414/4 "2017-04-06T01:02:04Z")

</div>

> [@krockssb](#):
>
> 1. I’ve tried to find in code methods where events callback from inline scripts (from this documentation [https://mitmproxy.org/doc/scripting/inlinescripts.html](https://mitmproxy.org/doc/scripting/inlinescripts.html) 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.

See [here](https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/script.py). To be clear, this is quite nontrivial Python code.

> [@krockssb](#):
>
> 1. Could you please also advise what method to import to override proxy start and configure it from script, like stickyMaster from old version?

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

---

<div class="post-metadata">

### Author: ![Krocks](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Krocks](https://discourse.mitmproxy.org/u/Krocks)
#### Post date: [May 10, 2017, 10:58am UTC](https://discourse.mitmproxy.org/t/setting-second-proxy-for-libmproxy/414/5 "2017-05-10T10:58:57Z")

</div>

This is still krockssb, but i forgot account.

> [@mhils](#):
>
> See here. To be clear, this is quite nontrivial Python code.
> 
> krockssb:

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.  
[/quote]

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.
