我是python的新手,仍在学习。我在 pythonanwhere 上创建了一个小的 python 3.6 Flask webapp,发现 send_file() 在 pythonanywhere 服务器上不起作用。我正在积极寻找直接在用户计算机上下载 excel 文件的替代方法。我也试过Response但它没有提供所需的输出。我在网上阅读了很多关于它的内容,发现如果我们在下面设置,send_file 可以正常工作
wsgi-disable-file-wrapper = True
但是,我不知道在哪里设置它,因为我找不到可以更新此行的 uWsgi.ini 文件。
以下是我尝试过但失败的方法,请帮助
SEND_FILE() 配置: ->>> 未运行..
output = BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')
workbook = writer.book
output.seek(0)
return send_file(output,attachment_filename="testing.xlsx",as_attachment=True)
Run Code Online (Sandbox Code Playgroud)
输出错误:
return environ.get('wsgi.file_wrapper', FileWrapper)(file, buffer_size)
SystemError: <built-in function uwsgi_sendfile> returned a result with an error set
Run Code Online (Sandbox Code Playgroud)
使用响应配置:
writer = pd.ExcelWriter("abc.xlsx", engine='xlsxwriter')
return Response(writer,mimetype="text/csv",headers={"Content-disposition":"attachment; filename=myplot.csv"})
Run Code Online (Sandbox Code Playgroud)
输出错误:
Error running WSGI application
TypeError: '_XlsxWriter' object is not iterable
File "/home/hridesh1987/.virtualenvs/myproject/lib/python3.6/site-packages/werkzeug/wsgi.py", line 870, in …Run Code Online (Sandbox Code Playgroud)