Issue
So I have this flask api script
@app.route('/request', methods=["POST"])
def reqpost():
content = request.get_json()
h = content['type']
if h == 'one'():
typeone()
return ("running type one")
elif h == 'two'():
typetwo()
return ("running type two")
else:
return ("error!")
and this is the json data that would be sent in a request
{
"type": "typeone"
}
but when I send a request to the server I get this on the server output
TypeError: 'str' object is not callable
for these lines
if h == 'one'():
# stuff
# and
elif h == 'two'():
# stuff
I have tried adding str() in those lines but I still get that dumb error
any help would be nice thanks :)
Solution
ty removing ()
:
@app.route('/request', methods=["POST"])
def reqpost():
content = request.get_json()
h = content['type']
if h == 'one':
typeone()
return ("running type one")
elif h == 'two':
typetwo()
return ("running type two")
else:
return ("error!")
Answered By - Tal Folkman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.