vcrpy
vcrpy copied to clipboard
async httpx streaming doesn't work
Steps to reproduce:
- 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).
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)
I suggest we close this one in view of #784