vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

fix: usage of io-like interface with VCR.py

Open tito opened this issue 11 months ago • 0 comments

This pull request aims to resolve an issue with using VCR.py in conjunction with io-like data. Let's have a look at this example:

@vcr.use_cassette("issue_vcr_aiohttp.yaml")
def test():
    test = io.BytesIO(b"hello")
    async with aiohttp.ClientSession() as session:
        async with session.post("https://httpbin.org/post", data=test, json=None) as response:
            ret = await response.json()
            assert ret["data"] == "hello"

It will trigger the assert, because the body received by aiohttp will be empty. When using cassette and building Request, the body is read() and later usage of body by aiohttp won't work.

Fix provided with the help of @kevdevg

tito avatar Jan 22 '25 01:01 tito