Pandas Python Flask从_目录发送_,返回损坏的文件

Pandas Python Flask从_目录发送_,返回损坏的文件,pandas,flask,openpyxl,sendfile,Pandas,Flask,Openpyxl,Sendfile,我们编写了代码,将一个文件从json转换为excel格式,并返回excel文件,就像我试图打开文件一样,它已损坏 我们尝试了pandas和openpyxl来转换json。 下面是用于检查一切是否正常的示例代码 from flask import request, send_from_directory df1 = pd.DataFrame([['a', 'b'], ['c', 'd']], index=['row 1', 'row 2'], columns=['col 1', 'col 2'])

我们编写了代码,将一个文件从json转换为excel格式,并返回excel文件,就像我试图打开文件一样,它已损坏

我们尝试了pandas和openpyxl来转换json。 下面是用于检查一切是否正常的示例代码

from flask import request, send_from_directory
df1 = pd.DataFrame([['a', 'b'], ['c', 'd']], index=['row 1', 'row 2'], columns=['col 1', 'col 2'])
df1.to_excel('/tmp/output.xlsx')
return send_from_directory('/tmp/', 'output' + '.xlsx', as_attachment=True)```

Notes: The code has been deployed using kubernetes, we have copied the generated file from the volume and its looking good, while transferring its getting corrupted. And we have tried different content types as well.


我在PPTX文件方面也面临同样的问题。使用curl下载文件,并且它工作正常

问题在于windows安全性

转到下载文件的属性。最后将出现取消阻止复选框。检查并按确定。现在再次尝试打开文件

您还可以检查两个文件的MD5是否匹配