refactor: query json content

This commit is contained in:
debugtalk
2018-07-25 17:32:12 +08:00
parent fe9d5c497b
commit dee51b6682
7 changed files with 32 additions and 22 deletions

View File

@@ -143,6 +143,9 @@ class ResponseObject(object):
if isinstance(body, (dict, list)):
# content = {"xxx": 123}, content.xxx
return utils.query_json(body, sub_query)
elif sub_query.isdigit():
# content = "abcdefg", content.3 => d
return utils.query_json(body, sub_query)
else:
# content = "<html>abcdefg</html>", content.xxx
err_msg = u"ParamsError: Failed to extract attribute from response body! => {}\n".format(field)
@@ -171,8 +174,8 @@ class ResponseObject(object):
msg += "\t=> {}".format(value)
logger.log_debug(msg)
# TODO: unify ParseResponseFailure type
except (exceptions.ParseResponseFailure, TypeError):
# TODO: remove except here
except (TypeError):
logger.log_error("failed to extract field: {}".format(field))
raise