From 0271e540c75ba69ee2d99e26a8b36f57545436c4 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 3 Jul 2020 19:17:46 +0800 Subject: [PATCH] fix: handle UnicodeDecodeError if failed to decode base64 content with utf-8 --- httprunner/ext/har2case/core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/httprunner/ext/har2case/core.py b/httprunner/ext/har2case/core.py index 7535270b..31796862 100644 --- a/httprunner/ext/har2case/core.py +++ b/httprunner/ext/har2case/core.py @@ -251,7 +251,12 @@ class HarParser(object): encoding = resp_content_dict.get("encoding") if encoding and encoding == "base64": - content = base64.b64decode(text).decode("utf-8") + content = base64.b64decode(text) + try: + content = content.decode("utf-8") + except UnicodeDecodeError: + logger.warning(f"failed to decode base64 content with utf-8 !") + return else: content = text