Приложение Python Dash: ссылка на скачивание flask.send_file() приводит к ошибке сервера

Приложение ниже работает при локальном запуске. Это не на рабочем сервере WSGI. Приложение отображается нормально, пока не нажата ссылка для скачивания, что приводит к ошибке сервера.

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import io
from flask import send_file

df = pd.DataFrame(data=[[1,2],[2,3]],columns=['A','B'])

app = dash.Dash()
server = app.server

app.layout = html.Div([html.Div('This is a test'),
                       html.A('download excel',href='/download_excel/')
                      ])

@app.server.route('/download_excel/')
def download_excel():
    memory = io.BytesIO()
    writer = pd.ExcelWriter(memory,engine='xlsxwriter')
    df.to_excel(writer,sheet_name='test')
    writer.save()
    memory.seek(0)
    return send_file(memory,attachment_filename='test.xlsx',as_attachment=True)

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

Ошибка заключается в следующем:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Что может быть причиной этого?

0 ответов

Другие вопросы по тегам