From fd1aaab3bfa8828e4238b25ae2dfc82908822285 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 16 May 2023 15:38:38 +0200 Subject: [PATCH] Respect urllib3.response.HTTPResponse.data --- vcr/stubs/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index c1c4654..5499d6c 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -249,12 +249,13 @@ class VCRConnection: # get the response response = self.real_connection.getresponse() + response_data = response.data if hasattr(response, "data") else response.read() # put the response into the cassette response = { "status": {"code": response.status, "message": response.reason}, "headers": serialize_headers(response), - "body": {"string": response.read()}, + "body": {"string": response_data}, } self.cassette.append(self._vcr_request, response) return VCRHTTPResponse(response)