【发布时间】:2018-10-09 19:03:41
【问题描述】:
我是 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)
输出错误:
return environ.get('wsgi.file_wrapper', FileWrapper)(file, buffer_size)
SystemError: <built-in function uwsgi_sendfile> returned a result with an error set
带有响应配置:
writer = pd.ExcelWriter("abc.xlsx", engine='xlsxwriter')
return Response(writer,mimetype="text/csv",headers={"Content-disposition":"attachment; filename=myplot.csv"})
输出错误:
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 __next__return self._next()
File "/home/hridesh1987/.virtualenvs/myproject/lib/python3.6/site-packages/werkzeug/wrappers.py", line 83, in _iter_encoded
for item in iterable:
【问题讨论】:
-
您是如何发现 send_file 在 PythonAnywhere 上不起作用的?据我所知,它应该有效吗?
-
@conrad 见pythonanywhere.com/forums/topic/8612
标签: python python-3.x flask pythonanywhere x-sendfile