1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 09:13:23 +00:00

Make json.loads of Python >=3.6 decode bytes by itself

Quoting https://docs.python.org/3/library/json.html#json.loads :
> Changed in version 3.6: s can now be of type bytes or bytearray.
> The input encoding should be UTF-8, UTF-16 or UTF-32.
This commit is contained in:
Sebastian Pipping
2023-07-07 19:49:18 +02:00
parent 4f70152e7c
commit 05f61ea56c
5 changed files with 9 additions and 12 deletions

View File

@@ -73,11 +73,8 @@ def _header_checker(value, header="Content-Type"):
def _transform_json(body):
# Request body is always a byte string, but json.loads() wants a text
# string. RFC 7159 says the default encoding is UTF-8 (although UTF-16
# and UTF-32 are also allowed: hmmmmm).
if body:
return json.loads(body.decode("utf-8"))
return json.loads(body)
_xml_header_checker = _header_checker("text/xml")