断言失败:运行脚本后,烧瓶服务器停止 [英] Assertion failed: Flask server stops after script is run

查看:56
本文介绍了断言失败:运行脚本后,烧瓶服务器停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个flask应用程序,当用户单击索引页面上的按钮时,他们会触发要生成的报告,并使用send_file()函数将其下载到他们的浏览器中.

I have a flask application that when the user clicks a button on the index page, they trigger a report to be generated and it is downloaded to their browser using the send_file() funtion.

每次创建并下载报告时,服务器都会停止运行,并且在终端中出现以下错误.每次都需要重新启动它,我不知道如何解决它.有任何想法吗?:)

Every time a report is created and downloaded the server stops and I get the below error in the terminal. It needs to be restarted every time and I can't figure out how to fix it. Any ideas? :)

flask_app.py文件:

flask_app.py file:

from flask import Flask, render_template, request, url_for, flash
import create_report
from flask_debugtoolbar import DebugToolbarExtension
from flask import send_file

app = Flask(__name__)
filename = ""

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/handle_data", methods=['GET', 'POST'])
def handle_data():
    text = request.form['accountinput']
    preprocessed_text = text.lower()
    filename = create_report.start_script(preprocessed_text)
    path = "reports/" + filename
    return send_file(path, as_attachment=True)

if __name__ == '__main__':
    app.run(debug=True)

终端错误:

Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.60.100/AppKit.subproj/NSView.m, line 14485.

推荐答案

您应使用

import matplotlib
matplotlib.use('Agg')

因为 create_report 模块使用 matplotlib ,而对于 matplotlib

since create_report module use matplotlib, and for matplotlib this is a common case.

这篇关于断言失败:运行脚本后,烧瓶服务器停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆