mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 11:36:56 +08:00
bugfix: ExtractFailure in Python2.7
This commit is contained in:
+5
-3
@@ -17,7 +17,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from httprunner import exceptions, logger
|
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
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
SECRET_KEY = "DebugTalk"
|
SECRET_KEY = "DebugTalk"
|
||||||
@@ -172,7 +172,7 @@ class FileUtils(object):
|
|||||||
|
|
||||||
def query_json(json_content, query, delimiter='.'):
|
def query_json(json_content, query, delimiter='.'):
|
||||||
""" Do an xpath-like query with json_content.
|
""" Do an xpath-like query with json_content.
|
||||||
@param (dict/list) json_content
|
@param (dict/list/string) json_content
|
||||||
json_content = {
|
json_content = {
|
||||||
"ids": [1, 2, 3, 4],
|
"ids": [1, 2, 3, 4],
|
||||||
"person": {
|
"person": {
|
||||||
@@ -194,11 +194,13 @@ def query_json(json_content, query, delimiter='.'):
|
|||||||
response_body = u"response body: {}\n".format(json_content)
|
response_body = u"response body: {}\n".format(json_content)
|
||||||
try:
|
try:
|
||||||
for key in query.split(delimiter):
|
for key in query.split(delimiter):
|
||||||
if isinstance(json_content, (list, str)):
|
if isinstance(json_content, (list, basestring)):
|
||||||
json_content = json_content[int(key)]
|
json_content = json_content[int(key)]
|
||||||
elif isinstance(json_content, dict):
|
elif isinstance(json_content, dict):
|
||||||
json_content = json_content[key]
|
json_content = json_content[key]
|
||||||
else:
|
else:
|
||||||
|
logger.log_error(
|
||||||
|
"invalid type value: {}({})".format(json_content, type(json_content)))
|
||||||
raise_flag = True
|
raise_flag = True
|
||||||
except (KeyError, ValueError, IndexError):
|
except (KeyError, ValueError, IndexError):
|
||||||
raise_flag = True
|
raise_flag = True
|
||||||
|
|||||||
Reference in New Issue
Block a user