# Replay and change upstream proxy server

**URL:** <https://discourse.mitmproxy.org/t/replay-and-change-upstream-proxy-server/1300>\
**Category:** help\
**Created:** [October 25, 2018, 3:19pm UTC](https://discourse.mitmproxy.org/t/replay-and-change-upstream-proxy-server/1300 "2018-10-25T15:19:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seb](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Seb](https://discourse.mitmproxy.org/u/Seb)\
**Post date:** [October 25, 2018, 3:19pm UTC](https://discourse.mitmproxy.org/t/replay-and-change-upstream-proxy-server/1300/1 "2018-10-25T15:19:36Z")

</div>

Hello,

I’m using python addons and I’m trying to change the upstream proxy server if a time out or a specific error occur in the response.

I’ve seen both work independently but when my flow is duplicated and sent through the ‘replay.client’ command, flow.live is not a “HttpLayer” object anymore and become just True giving me of course the following error: “AttributeError: ‘bool’ object has no attribute ‘change\_upstream\_proxy\_server’”

Here is my code:

```
def request(self, flow: mitmproxy.http.HTTPFlow):
    if flow.request.is_replay and flow.live:
        address = ('some_host', 8080)
        flow.live.change_upstream_proxy_server(address)

def responseheaders(self, flow: mitmproxy.http.HTTPFlow):
    if flow.response.status_code == 403:
        flow = flow.copy()
        ctx.master.commands.call("replay.client", [flow])

```

Am I missing something ?

---

<div class="post-metadata">

**Author:** ![Seb](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Seb](https://discourse.mitmproxy.org/u/Seb)\
**Post date:** [October 26, 2018, 1:26pm UTC](https://discourse.mitmproxy.org/t/replay-and-change-upstream-proxy-server/1300/2 "2018-10-26T13:26:51Z")

</div>

I finally managed to do what I wanted with the following code only:

```
def response(self, flow: mitmproxy.http.HTTPFlow):
        if flow.live and flow.response.status_code == 403:
                address = ('some_host', 8080)
                flow.live.change_upstream_proxy_server(address)
                flow.reply.kill(force=True)
                flow.response = None
                ctx.master.commands.call("replay.server", [flow])
```
