首页 > 解决方案 > 为什么在 Flask python 中使用 get 方法时出现错误

问题描述

我正在尝试通过在flask和python中使用get方法从url获取数据但得到

192.168.0.128 - - [22/Feb/2019 16:40:18] "TypeError: 'list' object is not callable
The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a list.
192.168.0.128 - - [22/Feb/2019 16:51:39] "GET /autocomplete?input=%27mumbai%27 HTTP/1.1" 500 -

网址:http://192.168.0.128:5000/autocomplete?input=%27mumbai%27

脚本:

app = Flask(__name__)
#cors = CORS(app)
cors = CORS(app, resources={r"/foo": {"origins": "http://localhost:port"}})

app.config['CORS_HEADERS'] = 'Content-Type'

@app.route('/autocomplete', methods=['GET']) 
@cross_origin(origin='localhost',headers=['Content- Type','Authorization'])
def AutoComplete():

    data = request.args.get('input')
    print (data)

    #http://192.168.0.128:5000/autocomplete=?input=mumbai

    spellchecker = SpellChecker()
    tokens = spellchecker.correct_phrase(data)
    result = AutoCompleter().guess_exercises(tokens)

    return result[:10]


if __name__ == '__main__':
    app.run(host='192.168.0.128', port=5000)

标签: pythonpython-3.xflask-restful

解决方案


有一个错误发回给您。该错误是错误404

来自 Wikipedia: 强调 HTTP 404、404 Not Found 和 404 错误消息是一种超文本传输​​协议 (HTTP) 标准响应代码,在计算机网络通信中,表示客户端能够与给定服务器通信,但服务器找不到请求的内容。

尝试将请求从更改/autocomplete//autocomplete


推荐阅读