Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在flaskpython中使用get方法时出错_Python_Python 3.x_Flask Restful - Fatal编程技术网

为什么在flaskpython中使用get方法时出错

为什么在flaskpython中使用get方法时出错,python,python-3.x,flask-restful,Python,Python 3.x,Flask Restful,我试图通过在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,

我试图通过在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 -
url:
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)

有一个错误被发回给你。那个错误就是错误

来自维基百科: 强调HTTP 404、404未找到和404错误消息是计算机网络通信中的超文本传输协议(HTTP)标准响应代码,用于指示客户端能够与给定服务器通信,但服务器无法找到请求的内容


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

而不是flask用户,因此这可能不是问题所在,但您将请求发送到
/autocomplete/
(尾随斜杠),同时将控制器映射到
'/autocomplete'
(无尾随斜杠)。这些url不相同。请尝试在返回结果之前将结果[:10]转换为json,API无法返回您想要的任何内容。。。。导入jsonify,然后返回jsonify(result[:10])现在的问题将是代码中的一个bug。请查看原始问题的评论。