Skip to content

Instantly share code, notes, and snippets.

@lapointexavier
Last active November 24, 2023 12:55
Show Gist options
  • Save lapointexavier/73e93bbfd3ba05738353bb257d3a09e1 to your computer and use it in GitHub Desktop.
Save lapointexavier/73e93bbfd3ba05738353bb257d3a09e1 to your computer and use it in GitHub Desktop.
Snippet to read a vcr cassette binary body
import json
import gzip
import base64
import StringIO
from vcr.serialize import deserialize
from vcr.serializers import yamlserializer
path = '../cassettes/api-InstagramAPITestCase-test_media.yml'
with open(path, 'r') as fh:
deserialized = deserialize(fh.read(), yamlserializer)
body_string = deserialized[1][0]['body']['string']
stio = StringIO.StringIO(body_string)
fio = gzip.GzipFile(fileobj=stio)
print(json.load(fio))
@coorasse
Copy link

coorasse commented Aug 6, 2020

A ruby version to achieve the same:

require 'yaml'
path = 'spec/vcr_cassettes/cassette.yml'
deserialized = YAML.load_file(path)
body_string = deserialized['http_interactions'][0]['response']['body']['string']
puts body_string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment