I have my script changing the upstream proxy for HTTP connections, but it seems to fail for HTTPS connections. Here's a basic stripped down example.
The script works fine for http://api.ipify.org/, but fails for https://api.ipify.org/. With HTTPS I see the following, which shows the upstream proxy wasn't changed.
Server connection to default_proxy:8888 failed: Error connecting to "default_proxy": [Errno 8] nodename nor servname provided, or not known
mitmdump -s utilities/proxy_redirects.py -U http://default_proxy:8888