python - 断言失败:脚本运行后 Flask 服务器停止
问题描述
我有一个烧瓶应用程序,当用户单击索引页面上的按钮时,他们会触发生成报告,并使用 send_file() 函数将其下载到浏览器。
每次创建和下载报告时,服务器都会停止,我在终端中收到以下错误。每次都需要重新启动,我不知道如何修复它。有任何想法吗?:)
flask_app.py 文件:
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
这是一个常见的情况。
推荐阅读
- haskell - Haskell 递归循环计数器
- javascript - 如何通过每种颜色在 Google 地图上获取形状绘制的 ID/数字顺序
- android - 如何在android中设置Imageview右端对齐到textview
- java - 无法将 gradle 项目导入 Eclipse Photon
- python - 如何在标记 Keras 时忽略字符
- groovy - 使用 WDS 在 Jmeter 中未正确显示绝对路径
- angular - Angular 6 指令:获取对主机组件实例的引用
- python - 如何打开文件并将项目附加到 Python 中的现有列表
- javascript - 内容隐藏/显示设计调整
- react-native - 在你听说 React Native Architecture 改变和 Airbnb,Udacity 放弃它之后,你采取了哪些行动?