def web_response_to_json(response):
"""
Modify the web response output to json format
param response: response object from requests library
return: json object representing the response content
"""
try:
if response:
resp_dict = json.loads(response.content)
except:
try:
resp_ordereddict = xmltodict.parse(response.content)
resp_json = json.dumps(resp_ordereddict, indent=4,
sort_keys=True)
resp_dict = json.loads(resp_json)
except:
raise exception.UnknownOutputFormat()
return resp_dict
评论列表
文章目录