You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"RuntimeError: Cannot change server.via on open connection" when using duplicate-modify-replay.py with upstream mode enabled #5241
I was using mitmdump.exe 7.0.4 for windows with the example duplicate-modify-replay.py without any problems.
After migrating to mitmdump.exe 8.0.0 I started to get the error below.
Addon error: Traceback (most recent call last):
File "duplicate-modify-replay.py", line 9, in request
flow = flow.copy()
File "mitmproxy\http.py", line 1254, in copy
File "mitmproxy\flow.py", line 170, in copy
File "mitmproxy\coretypes\serializable.py", line 39, in copy
File "mitmproxy\flow.py", line 165, in from_state
File "mitmproxy\flow.py", line 160, in set_state
File "mitmproxy\stateobject.py", line 47, in set_state
File "mitmproxy\stateobject.py", line 94, in make_object
File "mitmproxy\stateobject.py", line 56, in _process
File "mitmproxy\connection.py", line 331, in from_state
File "mitmproxy\connection.py", line 353, in set_state
File "mitmproxy\connection.py", line 299, in __setattr__
RuntimeError: Cannot change server.via on open connection.
Steps to reproduce the behavior:
1 - Create a script duplicate-modify-replay.py with the content below.
"""Take incoming HTTP requests and replay them with modified parameters."""
from mitmproxy import ctx
def request(flow):
# Avoid an infinite loop by not replaying already replayed requests
if flow.is_replay == "request":
return
flow = flow.copy()
# Only interactive tools have a view. If we have one, add a duplicate entry
# for our flow.
if "view" in ctx.master.addons:
ctx.master.commands.call("view.flows.add", [flow])
flow.request.path = "/changed"
ctx.master.commands.call("replay.client", [flow])
2 - Create a proxy (e.g. Burp Suite Proxy) running under port 8082
3 - Run mitmdump.exe 8.0.0 with the command below. mitmdump.exe --ssl-insecure --set add_upstream_certs_to_client_chain=true -s duplicate-modify-replay.py --mode upstream:http://127.0.0.1:8082
4 - If some request get stucked press Control+C and check the output.
Not sure if this is related but this happens when I try to read flows from a file - that has been recorded while using --set mode=upstream:http://
If I record the same request not using this parameter, everything just works.
I'm running 8.1.1
Not sure if this is related but this happens when I try to read flows from a file - that has been recorded while using --set mode=upstream:http:// If I record the same request not using this parameter, everything just works. I'm running 8.1.1
In connection.py find the line
if name in ("address", "via"):
and replace it with
if name == 'address':
There may be side effects so make note of the edit in source so you can undo if necessary, but this allows you to re-load flows where an upstream proxy was in use.
Reacted by Vaidas Kascėnas, PaperCube and Justin Yin
Are you certain that you replaced properly, and all instances? I'm not sure if there's more than 1 instance of it. You may be having a completely different issue. Not sure.
Probably because it's not fixed yet, PRs welcome. :)
is there a pypi release/publishing schedule?
We aim to ship mitmproxy 10 relatively soon to get more HTTP/3 feedback. The HTTP/3 implementation is still very experimental and we intentionally let it sit on main for a bit to iron out the worst bugs. :)
Not sure if this is related but this happens when I try to read flows from a file - that has been recorded while using --set mode=upstream:http:// If I record the same request not using this parameter, everything just works. I'm running 8.1.1
In connection.py find the line
if name in ("address", "via"):
and replace it with
if name == 'address':
There may be side effects so make note of the edit in source so you can undo if necessary, but this allows you to re-load flows where an upstream proxy was in use.
Activity
riramar commentedon Apr 5, 2022
Seems to be related to this commit 0f5b8c8
mhils commentedon Apr 6, 2022
Yeah - raising in
__setattr__is good, we need to fixcopy()to not trigger that I think. :)idb- commentedon Aug 23, 2022
Also having this issue.
kvaidas commentedon Oct 11, 2022
Not sure if this is related but this happens when I try to read flows from a file - that has been recorded while using --set mode=upstream:http://
If I record the same request not using this parameter, everything just works.
I'm running 8.1.1
idb- commentedon Oct 17, 2022
In connection.py find the line
and replace it with
There may be side effects so make note of the edit in source so you can undo if necessary, but this allows you to re-load flows where an upstream proxy was in use.
riramar commentedon Nov 3, 2022
I'm still having this issue on mitmproxy 9.0.1.
idb- commentedon Nov 5, 2022
Are you certain that you replaced properly, and all instances? I'm not sure if there's more than 1 instance of it. You may be having a completely different issue. Not sure.
riramar commentedon Nov 5, 2022
It's the same error. I did the same test again from the past (using mitmproxy-9.0.1-windows.zip) with the same file and got the same error.
The same test using the version 7.0.4 it works properlly.
This seems to be related to this commit 0f5b8c8
Sim4n6 commentedon Mar 16, 2023
cole-nayya commentedon May 11, 2023
@mhils is there a pypi release/publishing schedule? This issue is still occurring in v9.0.1
mhils commentedon May 14, 2023
Probably because it's not fixed yet, PRs welcome. :)
We aim to ship mitmproxy 10 relatively soon to get more HTTP/3 feedback. The HTTP/3 implementation is still very experimental and we intentionally let it sit on main for a bit to iron out the worst bugs. :)
cole-nayya commentedon May 16, 2023
This doesn't happen on the tip/10.0.0.dev0 - at least with the examples I have - otw would be happy to contribute.
mhils commentedon May 16, 2023
Thanks for the triage, that's a great contribution in itself. 😄 🍰
3052 commentedon May 20, 2024
confirming above comment - looks like https://mitmproxy.org/downloads/#10.0.0/ is the first working version
cogitozz commentedon Sep 23, 2024
Hi, is there a good solution? I'm still having this issue on mitmproxy 10.4.2
Ad3n1ne commentedon May 20, 2025
我修改了这部分代码也解决了这个问题 想了解具体的原理是什么?