PYTHON |用自定义文本替换 json 响应
PYTHON | Replace json response with custom text
所以我有一个简单的 python 脚本来打印网站 post 请求的状态代码...
这是我得到的输出:
{"success": false, "error": "Incomplete request"}
但我希望它改为打印:
Error! Incomplete Request
这可能吗?谢谢!
你的意思是这样的吗:
# suppose response={"success": false, "error": "Incomplete request"}
# I suppose false is False since the dict should have been decoded from json to Python
if (not response['success'] and response['error'] == 'Incomplete request'):
print('Error! Incomplete request')
Python3:
if not response['success']:
print(f"Error! {response['error']}")
python2:
if not response['success']:
print("Error! {0}".format(response['error']))
所以我有一个简单的 python 脚本来打印网站 post 请求的状态代码...
这是我得到的输出:
{"success": false, "error": "Incomplete request"}
但我希望它改为打印:
Error! Incomplete Request
这可能吗?谢谢!
你的意思是这样的吗:
# suppose response={"success": false, "error": "Incomplete request"}
# I suppose false is False since the dict should have been decoded from json to Python
if (not response['success'] and response['error'] == 'Incomplete request'):
print('Error! Incomplete request')
Python3:
if not response['success']:
print(f"Error! {response['error']}")
python2:
if not response['success']:
print("Error! {0}".format(response['error']))