Skip to content

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

Open
@tito

Description

@tito

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      aiohttp have empty body when body is a io-like object · Issue #907 · kevin1024/vcrpy