title: Mitmproxy upstream server
body: <p>Trying to set upstream server in mitmproxy.</p>
  
  <p>The scheme is very simple: Browser -> Mitmproxy -> Proxy -> AnyServer</p>
  
  <p>Here is the code:
      import mitmproxy
      from mitmproxy.models import HTTPResponse
      from netlib.http import Headers
      from mitmproxy import ctx</p>
  
  <pre><code>def request (flow):
      if flow.request.method == "CONNECT":
          return
      if flow.live:
          print (flow.request.host)
          address = ("92.247.125.246", 3128)
          flow.live.change_upstream_proxy_server(address)
  </code></pre>
  
  <p>After this a had the SetServerNotAllowedException:</p>
  
  <p><a href="https://i.stack.imgur.com/ITfgQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ITfgQ.png" alt="enter image description here"></a></p>
  
  <p>I disabled HTTP/2 in my browser and now there is no errors, but on myip sites I see the IP of my  MITM proxy server! So it is not using the last proxy, why? Any ideas please?</p>