From 50f015bd7a96b2cf5362680cb9508336a22ade32 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 4 Jun 2020 16:28:11 +0800 Subject: [PATCH] change: update capture exception --- httprunner/client.py | 4 ++-- httprunner/ext/har2case/core.py | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/httprunner/client.py b/httprunner/client.py index 0923d16e..01f10e0a 100644 --- a/httprunner/client.py +++ b/httprunner/client.py @@ -48,14 +48,14 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData: if request_body is not None: try: request_body = json.loads(request_body) - except json.JSONDecodeError as ex: + except json.JSONDecodeError: # str: a=1&b=2 pass except UnicodeDecodeError as ex: # bytes/bytearray: request body in protobuf capture_exception(ex) except TypeError as ex: - # neither str nor bytes/bytearray + # neither str nor bytes/bytearray, e.g. capture_exception(ex) request_content_type = lower_dict_keys(request_headers).get("content-type") diff --git a/httprunner/ext/har2case/core.py b/httprunner/ext/har2case/core.py index 5834c696..3c491cf5 100644 --- a/httprunner/ext/har2case/core.py +++ b/httprunner/ext/har2case/core.py @@ -167,8 +167,8 @@ class HarParser(object): try: post_data = json.loads(post_data) request_data_key = "json" - except JSONDecodeError as ex: - capture_exception(ex) + except JSONDecodeError: + pass elif mimeType.startswith("application/x-www-form-urlencoded"): post_data = utils.convert_x_www_form_urlencoded_to_dict(post_data) else: @@ -238,16 +238,12 @@ class HarParser(object): try: resp_content_json = json.loads(content) - except JSONDecodeError as ex: - capture_exception(ex) - logger.warning( - "response content can not be loaded as json: {}".format( - content.encode("utf-8") - ) - ) + except JSONDecodeError: + logger.warning(f"response content can not be loaded as json: {content}") return if not isinstance(resp_content_json, dict): + # e.g. ['a', 'b'] return for key, value in resp_content_json.items():