vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

async httpx streaming doesn't work

Open AGhost-7 opened this issue 3 years ago • 2 comments

Steps to reproduce:

  1. Use vcrpy with async httpx along with chunked http. E.g.:
    with vcr.use_cassette("sample.yml"):
        async with client.stream(
                "POST",
                "/sample-path"
                },
            ) as response:
              async for chunk in response.aiter_lines():
                print('chunk', chunk)



Expected behaviour: it successfully records / replays content.

Actual behaviour: I get an exception: vcr/stubs/httpx_stubs.py:72: IndexError. httpx's stream method calls send with no args (only kwargs).

AGhost-7 avatar Jul 16 '21 17:07 AGhost-7

Same issue with the sync version, with the latest release (v4.2.1).

Sample code to reproduce:

with httpx.stream("GET", "<URL>") as response:
    for chunk in response.iter_bytes():
        print(chunk)

Error:

cassette = <vcr.cassette.Cassette object at 0x7f3430d1aa10>, real_send = <function Client.send at 0x7f34369e7d90>, args = (<httpx.Client object at 0x7f3430d2dba0>,)
kwargs = {'auth': None, 'follow_redirects': False, 'request': <Request('GET', '<URL>')>, 'stream': True}

    def _shared_vcr_send(cassette, real_send, *args, **kwargs):
>       real_request = args[1]
E       IndexError: tuple index out of range

.venv/lib/python3.10/site-packages/vcr/stubs/httpx_stubs.py:79: IndexError

This works fine with get instead of stream:

response = httpx.get("<URL>")
for chunk in response.iter_bytes():
    print(chunk)

kukovecz avatar Nov 25 '22 09:11 kukovecz

I suggest we close this one in view of #784

parkerhancock avatar Dec 08 '23 19:12 parkerhancock