所以我有这个flask api脚本
@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!")
这是在请求中发送的json数据
{ "type": "typeone" }
但是当我向服务器发送请求时,我会在服务器输出中得到这个
TypeError:“str”对象不可调用
对于这些线路
if h == 'one'(): # stuff # and elif h == 'two'(): # stuff
我曾尝试在这些行中添加str(),但仍然会出现那个愚蠢的错误
任何帮助都很好,谢谢:)
去蒂 () :
()
@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!")