vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

aiohttp have empty body when body is a io-like object

Open tito opened this issue 11 months ago • 0 comments

When using aiohttp and sending a open file as a body (here as io.BytesIO), when using VCR.py, the initial Request construction is consuming the body, so when aiohttp is getting the data, it's empty as VCR.py don't seek back.

@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"

Here is a PR #906 that fix this issue, by ensuring the body is seek back after reading.

tito avatar Jan 22 '25 01:01 tito