question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

aiohttp streaming fails on initial cassette recording

See original GitHub issue

When using the aiohttp Streaming API and recording a new cassette the actual data read will fail, although the cassette is successfully recorded and subsequent tests pass.

Minimal example:

    # Will fail on initial record, but succeed after that
    with vcr.use_cassette('./vcrpytest1.yaml'):
        async with aiohttp.ClientSession() as session:
            async with session.get('https://httpbin.org/range/50') as response:
                byts = b''
                async for data in response.content.iter_chunked(1024*1024):
                    byts += data
                assert len(byts) == 50

    # Fails everytime
    with vcr.use_cassette('./vcrpytest1.yaml', record_mode='all'):
        async with aiohttp.ClientSession() as session:
            async with session.get('https://httpbin.org/range/50') as response:
                byts = b''
                async for data in response.content.iter_chunked(1024*1024):
                    byts += data
                assert len(byts) == 50

Run with Python 3.7.4: aiohttp==3.6.2 vcrpy==3.0.0

I also created a gist that runs through a few different scenarios: https://gist.github.com/mikemoritz/01f7f222f9353846db16a6d07d98d806#file-vcrpytest-py

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nickdirienzocommented, Dec 19, 2019

Ah! Nice find! And thanks for the detailed investigation @mikemoritz 🙏

Dang, there really isn’t a way to unread. That API is being deprecated in the future so we can’t rely on that…

Thinking aloud here: I’m a tad worried about returning the mock response initially because I don’t think the vcrpy mock response maps directly to the aiohttp response object. However, I think it means that we should be moving towards ensuring they’re as close as possible. I can’t remember if the other clients behave this way, so this might be alright.

I know that play_responses also marks the response as played, so as long as that doesn’t interfere with being able to make requests multiple times in the same test run, then that seems like a good approach. It’d be really cool if we could unread but 🤷‍♂

I’m using aiohttp in my day to day, so this is a neat way to continue learning about it. I don’t have time to work on this library during the day; it’s more of a nights and weekends kinda deal for me right now. If that’s okay with y’all, I’m happy to help review and help here best I can!

0reactions
mikemoritzcommented, Dec 19, 2019

Sure thing. When I have some spare minutes there were a few other avenues I wanted to investigate first since I appreciate that returning the mock response initially is a fundamental change for all users to solve a lower percentage use case (probably).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Streaming API — aiohttp 3.8.3 documentation
The reader from incoming stream. User should never instantiate streams manually but use existing aiohttp.web.BaseRequest.content and aiohttp.ClientResponse.
Read more >
Trying to stream telegram media and playing it in a web page
I am using this script to stream Telegram videos to a web server. It uses Telethon and AIOhttp to stream the file. The...
Read more >
cEe - River Thames Conditions - Environment Agency - GOV.UK
Beachwear brands online, Wixners kran, Red hymn for the missing album, Glosario de terminos financieros sbs, Fiji first class, Nolo press wills, The...
Read more >
Speeding Up Python with Concurrency, Parallelism, and asyncio
In Python, there are a few different ways to achieve concurrency. The first we'll take a look at is the threading library. For...
Read more >
Better performance with tf.function | TensorFlow Core
Graph . Function bridges this gap by separating your code in two stages: 1) In the first stage, referred to as "tracing", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found