From e2363b1f2d739b3b8706caa19cc6b37c9cfb5f61 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 26 Jul 2018 12:17:57 +0800 Subject: [PATCH] bugfix: ExtractFailure in Python2.7 --- httprunner/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/httprunner/utils.py b/httprunner/utils.py index 04ad8825..edc98c73 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -17,7 +17,7 @@ from datetime import datetime import yaml from httprunner import exceptions, logger -from httprunner.compat import OrderedDict, is_py2, is_py3, str +from httprunner.compat import OrderedDict, basestring, is_py2, is_py3, str from requests.structures import CaseInsensitiveDict SECRET_KEY = "DebugTalk" @@ -172,7 +172,7 @@ class FileUtils(object): def query_json(json_content, query, delimiter='.'): """ Do an xpath-like query with json_content. - @param (dict/list) json_content + @param (dict/list/string) json_content json_content = { "ids": [1, 2, 3, 4], "person": { @@ -194,11 +194,13 @@ def query_json(json_content, query, delimiter='.'): response_body = u"response body: {}\n".format(json_content) try: for key in query.split(delimiter): - if isinstance(json_content, (list, str)): + if isinstance(json_content, (list, basestring)): json_content = json_content[int(key)] elif isinstance(json_content, dict): json_content = json_content[key] else: + logger.log_error( + "invalid type value: {}({})".format(json_content, type(json_content))) raise_flag = True except (KeyError, ValueError, IndexError): raise_flag = True