Open evgeni opened 5 years ago
Thank you for reporting this bug! Much appreciated.
We recently released v2.1.0
with a lot of fixes. Although this doesn't look like one of the fixes included. Could you try with the latest version too so we can rule that out before proceeding?
Would you be open to contributing a pull request to address this? I'd be more than happy to collaborate getting the TravisCI to pass to get it over the line. Then we can put out a fix shortly.
If you haven't got the bandwidth, that's fine too. Is there a toy repo that we could clone to replicate the issue at least?
Hey,
so as you expected, 2.1.0 doesn't fix the issue. And I must admit I don't really have the bandwidth to dive into the details of VCR itself to help you fixing this. However, I sat down and made you a smaller reproducer, so that's something ;)
import time
import requests
import vcr
URL = 'https://www.die-welt.net/'
with vcr.use_cassette('test.yaml', record_mode='all'):
s = requests.Session()
s.verify = False
s.get(URL)
time.sleep(10)
s.get(URL)
If I am not mistaken, you can point URL
at any Apache httpd in default config, and it will have KeepAliveTimeout 5
and thus fail if you try a second GET
after 10 seconds.
Awesome! I’ll have a crack at replicating it myself with that sample. That’s really helpful thanks.
I can confirm that this is still an issue with vcrpy
4.1.0. It took me a while to figure out that vcrpy
is causing the problem and not the remote server, as the error message can be pretty misleading. I'd appreciate if this issue could get fixed.
Hello! I am also one of the unfortunate ones who has encountered this issue. Thankfully I managed to debug and fix it. See PR https://github.com/kevin1024/vcrpy/pull/605.
vcrpy 2.0.1, requests 2.22.0
We are using requests with sessions to call an API endpoint to trigger a job and then call another endpoint in a loop to get the job status and thus wait until the job is done. The server is an Apache httpd with
KeepAliveTimeout 5
and a Rails app.The code is working fine outside of VCR, but as soon as we enable VCR recording, the "wait" part of the code fails (
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))
on Python 2.7,requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
on Python 3.7)Example code:
output:
As you can see, the server answers with
'keep-alive': 'timeout=5, max=10000'
to thePOST
, but we usetime.sleep(10)
to wait. Lowering thesleep
to 4 (so below the timeout) avoids the problem. However, it should be the responsibility of the underlying http client to re-open the connection if needed. Andrequests
does so just fine if used outside ofVCR
. Thus we think this is a bug in VCR.