python - 为什么在 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)
解决方案
有一个错误发回给您。该错误是错误404。
来自 Wikipedia: 强调 HTTP 404、404 Not Found 和 404 错误消息是一种超文本传输协议 (HTTP) 标准响应代码,在计算机网络通信中,表示客户端能够与给定服务器通信,但服务器找不到请求的内容。
尝试将请求从更改/autocomplete/
为/autocomplete
推荐阅读
- websocket - 使用 webclient(websocket.js)的 ejabberd 连接失败
- git - git:如何压缩多个合并提交
- image - 从头弹起然后倒置
- nginx - 用于编译动态模块的 nginx ./configure 在哪里?
- python - UnboundLocalError:分配前引用的局部变量“med”
- ruby - 在某些情况下,红宝石空格是否敏感?
- android - Android Canvas 改变形状和文本交集的颜色
- python - 在 Python 中将嵌套的 JSON 数组转换为简单的 JSON
- javascript - 如何在 jquery Datatable 上应用 columnDefs 并将 saveState 选项设置为 true
- ruby - 使用 docker 日志在 docker 容器中看不到 ruby 进程输出