kevin1024 / vcrpy

Automatically mock your HTTP interactions to simplify and speed up testing
MIT License
2.72k stars 388 forks source link

[BUG] Doesn't work for URL's beginning with www. #770

Closed jake-chambers closed 1 year ago

jake-chambers commented 1 year ago

This works:

# @vcr.use_cassette(f'{get_test_directory()}/result.yaml')
def test_thing():
    res = requests.request(
        url="https://dummyjson.com/products/1",
        headers={
            "Content-Type": "application/json",
        },
        method="GET",
        data={},
    )
    res.raise_for_status()

This doesn't:

@vcr.use_cassette(f'{get_test_directory()}/result.yaml')
def test_thing():
    res = requests.request(
        url="https://dummyjson.com/products/1",
        headers={
            "Content-Type": "application/json",
        },
        method="GET",
        data={},
    )
    res.raise_for_status()

Adding cassette causes AttributeError: 'HTTPSConnection' object has no attribute 'assert_hostname'

Stack trace:

api-venv/lib/python3.11/site-packages/requests/api.py:59: in request
    return session.request(method=method, url=url, **kwargs)
api-venv/lib/python3.11/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
api-venv/lib/python3.11/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)
api-venv/lib/python3.11/site-packages/requests/adapters.py:486: in send
    resp = conn.urlopen(
api-venv/lib/python3.11/site-packages/urllib3/connectionpool.py:703: in urlopen
    httplib_response = self._make_request(
api-venv/lib/python3.11/site-packages/urllib3/connectionpool.py:440: in _make_request
    httplib_response = conn.getresponse(buffering=True)
api-venv/lib/python3.11/site-packages/contextlib2/__init__.py:181: in __exit__
    self.gen.throw(type, value, traceback)
api-venv/lib/python3.11/site-packages/vcr/patch.py:331: in force_reset
    yield
api-venv/lib/python3.11/site-packages/vcr/stubs/__init__.py:251: in getresponse
    self.real_connection.request(
api-venv/lib/python3.11/site-packages/urllib3/connection.py:239: in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
../../../.pyenv/versions/3.11.4/lib/python3.11/http/client.py:1286: in request
    self._send_request(method, url, body, headers, encode_chunked)
../../../.pyenv/versions/3.11.4/lib/python3.11/http/client.py:1332: in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
../../../.pyenv/versions/3.11.4/lib/python3.11/http/client.py:1281: in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
../../../.pyenv/versions/3.11.4/lib/python3.11/http/client.py:1041: in _send_output
    self.send(msg)
../../../.pyenv/versions/3.11.4/lib/python3.11/http/client.py:979: in send
    self.connect()