Skip to content

Instantly share code, notes, and snippets.

@Sjord
Created February 8, 2016 13:50
Show Gist options
  • Save Sjord/06bede5fb2702b360413 to your computer and use it in GitHub Desktop.
Save Sjord/06bede5fb2702b360413 to your computer and use it in GitHub Desktop.
import vcr
import urllib2
import os
yaml_file = 'reproduce.yaml'
# Begin with existing YAML file with non-matching requests.
try:
os.remove(yaml_file)
except OSError:
pass
with vcr.use_cassette(yaml_file):
urllib2.urlopen('https://github.com/kevin1024/vcrpy').read()
# Request same URL several times.
with vcr.use_cassette(yaml_file, record_mode='new_episodes'):
for i in range(10):
response = urllib2.urlopen('https://httpbin.org/bytes/4').read()
print response.encode('hex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment