Reputation: 435
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 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)
Error in terminal:
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.
Upvotes: 3
Views: 4118
Reputation: 2087
You should start your program with
import matplotlib
matplotlib.use('Agg')
since create_report
module use matplotlib
, and for matplotlib
this is a common case.
Upvotes: 14