diff --git a/vcr/filters.py b/vcr/filters.py index 7f33155..f2d389a 100644 --- a/vcr/filters.py +++ b/vcr/filters.py @@ -113,7 +113,10 @@ def replace_post_data_parameters(request, replacements): if sep is None: new_splits.append((k, sep, ov)) else: - rk = k.decode("utf-8") + try: + rk = k.decode("utf-8") + except UnicodeDecodeError: + rk = k if rk not in replacements: new_splits.append((k, sep, ov)) else: diff --git a/vcr/stubs/httpx_stubs.py b/vcr/stubs/httpx_stubs.py index 65d56cf..d57a433 100644 --- a/vcr/stubs/httpx_stubs.py +++ b/vcr/stubs/httpx_stubs.py @@ -106,7 +106,12 @@ def _from_serialized_response(request, serialized_response, history=None): def _make_vcr_request(httpx_request, **kwargs): - body = httpx_request.read().decode("utf-8") + body_bytes = httpx_request.read() + try: + body = body_bytes.decode("utf-8") + except UnicodeDecodeError: + body = body_bytes + uri = str(httpx_request.url) headers = dict(httpx_request.headers) return VcrRequest(httpx_request.method, uri, body, headers)