1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 01:25:34 +00:00

Fix for Serialization errors with JSON adapter

This patch aims to fix the issue#222,
where json data in request can not be serialized
because of TypeError in py3
This commit is contained in:
Aliaksandr Buhayeu
2015-12-02 16:33:58 +03:00
committed by Kevin McCarthy
parent 528c9e7b1a
commit 9daf301deb
4 changed files with 96 additions and 19 deletions

View File

@@ -9,16 +9,21 @@ def deserialize(cassette_string):
def serialize(cassette_dict):
error_message = (
"Does this HTTP interaction contain binary data? "
"If so, use a different serializer (like the yaml serializer) "
"for this request?"
)
try:
return json.dumps(cassette_dict, indent=4)
except UnicodeDecodeError as original:
except UnicodeDecodeError as original: # py2
raise UnicodeDecodeError(
original.encoding,
b"Error serializing cassette to JSON",
original.start,
original.end,
original.args[-1] +
("Does this HTTP interaction contain binary data? "
"If so, use a different serializer (like the yaml serializer) "
"for this request?")
original.args[-1] + error_message
)
except TypeError as original: # py3
raise TypeError(error_message)