Issue
I have an odd behavior for one of my endpoints in my Flask application which accepts boolean query parameters. No matter what I pass to it, such as asfsdfd
or true
or false
, it is considered true. Only by leaving it empty does it become false.
full_info = request.args.get("fullInfo", default=False, type=bool)
if full_info:
# do stuff
It seems to be that either any input is considered to be true. Is there any way to make this work with the Flask intended way of defining the type, or do I need to accept a string and compare it?
Solution
This is expected as query string is an actual string, hence when you get a string no matter what it is, if it's not empty, it will be true. As in:
>>>bool('False')
True
You will have to do string comparison if you want to get a boolean.
Answered By - dmitrybelyakov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.