Python 未能结束烧瓶应用程序

Python 未能结束烧瓶应用程序,python,flask,internal-server-error,Python,Flask,Internal Server Error,我有一个烧瓶应用程序,如下所示: socketio2.run(app2, host="0.0.0.0", port=4998) def shutdown_server(): func = request.environ.get('werkzeug.server.shutdown') if func is None: raise RuntimeError('Not running with the Werkzeug Server') func() @ap

我有一个烧瓶应用程序,如下所示:

socketio2.run(app2, host="0.0.0.0", port=4998)
def shutdown_server():
    func = request.environ.get('werkzeug.server.shutdown')
    if func is None:
        raise RuntimeError('Not running with the Werkzeug Server')
    func()

@app2.route('/shutdown', methods=['POST'])
def shutdown():
    shutdown_server()
    print " shutdown"
    return 'Server shutting down...'
我创建了一个方法来结束它,如下所示:

socketio2.run(app2, host="0.0.0.0", port=4998)
def shutdown_server():
    func = request.environ.get('werkzeug.server.shutdown')
    if func is None:
        raise RuntimeError('Not running with the Werkzeug Server')
    func()

@app2.route('/shutdown', methods=['POST'])
def shutdown():
    shutdown_server()
    print " shutdown"
    return 'Server shutting down...'
我得到以下错误

内部服务器错误

服务器遇到内部错误,无法完成 你的要求。服务器过载或中存在错误 应用程序


我的目标是结束这个Flask应用程序,然后运行Python脚本。有什么建议吗?

由于您将服务器作为socketio服务器运行,默认的关闭服务器代码将不起作用。但是,socketio确实提供了一个要停止的包装器,当您使用它时,默认行为应该停止服务器

因此,如果您将代码修改为以下内容-

def shutdown_server():
    socketio2.stop()

然后它应该完成任务

您是否导入了请求模块?i、 e.:
来自烧瓶导入请求
是,我已导入