Skip to content

Commit 2824cfd

Browse files
committed
fix based on kevin1024/vcrpy#844
1 parent db764f0 commit 2824cfd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

vcr/filters.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def replace_post_data_parameters(request, replacements):
113113
if sep is None:
114114
new_splits.append((k, sep, ov))
115115
else:
116-
rk = k.decode("utf-8")
116+
try:
117+
rk = k.decode("utf-8")
118+
except UnicodeDecodeError:
119+
rk = k
117120
if rk not in replacements:
118121
new_splits.append((k, sep, ov))
119122
else:

vcr/stubs/httpx_stubs.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ def _from_serialized_response(request, serialized_response, history=None):
106106

107107

108108
def _make_vcr_request(httpx_request, **kwargs):
109-
body = httpx_request.read().decode("utf-8")
109+
body_bytes = httpx_request.read()
110+
try:
111+
body = body_bytes.decode("utf-8")
112+
except UnicodeDecodeError:
113+
body = body_bytes
114+
110115
uri = str(httpx_request.url)
111116
headers = dict(httpx_request.headers)
112117
return VcrRequest(httpx_request.method, uri, body, headers)

0 commit comments

Comments
 (0)