From ca395771756f36ab25f93e6d929fb023b55a1dcc Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 14 May 2018 17:14:44 +0800 Subject: [PATCH] bugfix: make compatible with download api that response in bytes --- httprunner/__about__.py | 2 +- httprunner/report.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/httprunner/__about__.py b/httprunner/__about__.py index a14324da..b16e7be7 100644 --- a/httprunner/__about__.py +++ b/httprunner/__about__.py @@ -1,7 +1,7 @@ __title__ = 'HttpRunner' __description__ = 'One-stop solution for HTTP(S) testing.' __url__ = 'https://github.com/HttpRunner/HttpRunner' -__version__ = '1.4.3' +__version__ = '1.4.4' __author__ = 'debugtalk' __author_email__ = 'mail@debugtalk.com' __license__ = 'MIT' diff --git a/httprunner/report.py b/httprunner/report.py index 9dedd1a5..cc6dcce5 100644 --- a/httprunner/report.py +++ b/httprunner/report.py @@ -118,14 +118,17 @@ def stringify_body(meta_data, request_or_response): elif isinstance(body, bytes): resp_content_type = headers.get("Content-Type", "") - if "image" in resp_content_type: - meta_data["response_data_type"] = "image" - body = "data:{};base64,{}".format( - resp_content_type, - b64encode(body).decode('utf-8') - ) - else: - body = body.decode("utf-8") + try: + if "image" in resp_content_type: + meta_data["response_data_type"] = "image" + body = "data:{};base64,{}".format( + resp_content_type, + b64encode(body).decode('utf-8') + ) + else: + body = body.decode("utf-8") + except UnicodeDecodeError: + pass elif not isinstance(body, (basestring, numeric_types, Iterable)): # class instance, e.g. MultipartEncoder()