I have made an API app using flask, that takes a number(decimal) as input and returns some string. This app breaks if I send a string and works fine after re-starting it. I don\
You need to trigger a return with an error message, if whatever the user submits can't be expressed as an integer.
The following should work for submissions like 3
and '3'
# now the processing part
try:
number = int(json_data['number'])
except ValueError:
return jsonify(['Invalid submission'])
# Number is now type integer
if number < 2:
return jsonify(["the number is less than two"])
else:
return jsonify(["the number is not less than two"])