mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-20 03:52:09 +08:00
fix: add ExtendJSONEncoder to safely dump json data with python object, such as MultipartEncoder
This commit is contained in:
@@ -212,3 +212,14 @@ def ensure_file_path_valid(file_path: Text) -> Text:
|
||||
|
||||
new_file_path = os.path.join(os.getcwd(), f"{os.sep.join(path_names)}{file_suffix}")
|
||||
return new_file_path
|
||||
|
||||
|
||||
class ExtendJSONEncoder(json.JSONEncoder):
|
||||
""" especially used to safely dump json data with python object, such as MultipartEncoder
|
||||
"""
|
||||
|
||||
def default(self, obj):
|
||||
try:
|
||||
return super(ExtendJSONEncoder, self).default(obj)
|
||||
except (UnicodeDecodeError, TypeError):
|
||||
return repr(obj)
|
||||
|
||||
Reference in New Issue
Block a user