so I have a simple python script to print a status code of a website post request...
This is the output I am getting:
{"success": false, "error": "Incomplete request"}
But I want it to print this instead:
Error! Incomplete Request
Is this possible? Thanks!
CodePudding user response:
Do you mean something like this:
# 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')
CodePudding user response:
Python3:
if not response['success']:
print(f"Error! {response['error']}")
python2:
if not response['success']:
print("Error! {0}".format(response['error']))
