vcrpy
vcrpy copied to clipboard
Proxy address ends up in in cassette `uri`s
When using with a http/https HTTPS_PROXY set in the environment, and the requests or urlllib3 libs to access some URLs, recorded cassettes' uri end up being prefixed by the proxy URL.
This is problematic because the cassette can then not be played back without having the same proxy settings in effect -- different ones cause different uris in cassettes and cause non-matching.
This hampers sharing of cassettes e.g. in git because different setups need different proxies, some don't need one at all, etc.
Reproducer:
$ docker run --rm -dp 3128:3128 ubuntu/squid
e0c6faf........
$ cat bug914.py
import vcr
import requests
with vcr.use_cassette("bug914.yaml"):
response = requests.get("https://vcrpy.readthedocs.io/en/latest/")
print(response)
$ env HTTPS_PROXY=http://localhost:3128 python3 bug914.py
<Response [200]>
$ grep -F uri: bug914.yaml
uri: https://localhost:3128/en/latest/
Now, if we try to use that cassette without the proxy in effect:
$ env HTTPS_PROXY= python3 bug914.py
Traceback (most recent call last):
[redacted]
No match for the request (<Request (GET) https://vcrpy.readthedocs.io/en/latest/>) was found.
Found 1 similar requests with 2 different matcher(s) :
1 - (<Request (GET) https://localhost:3128/en/latest/>).
Matchers succeeded : ['method', 'scheme', 'path', 'query']
Matchers failed :
host - assertion failure :
vcrpy.readthedocs.io != localhost
port - assertion failure :
443 != 3128
This is with:
$ uv pip list | grep -E '^requests|^urllib3|^vcrpy'
requests 2.32.3
urllib3 2.3.0
vcrpy 7.0.0
I think @alga fixed this and it's in the mainline branch, just waiting for a release.
Yeah, this sems to be a duplicate of https://github.com/kevin1024/vcrpy/pull/809