我想实现 通过调取 django 的 api,然后下载一个 excel 文件, 不过目前遇到的情况是,返回了乱码的字节流,并不是文件,求助

1 manzhiyong Sep 16, 2020 from openpyxl import Workbook .... .... wb = Workbook() ..... ...... respOnse= HttpResponse(content_type='application/msexcel') response['Content-Disposition'] = 'attachment; filename=xxx.xls' wb.save(response) return response |
2 dwadewyp OP @manzhiyong 我就是这么做的。。。 通过 postman 返回的是乱码的字节流 |
3 dwadewyp OP @manzhiyong respOnse= HttpResponse(content_type='application/ms-excel') response['Content-Disposition'] = 'attachment; filename="ThePythonDjango.xls"' ws.save(response) return response |
4 bolide2005 Sep 16, 2020 content type 改成 application/x-xls 试试? |
5 manzhiyong Sep 16, 2020 https://baijiahao.baidu.com/s?id=1666379708328635331&wfr=spider&for=pc 你点的是文章里的 send and download 吗 |
6 dwadewyp OP @manzhiyong 感谢 |
7 sunmlight Sep 16, 2020 有可能是文件名的原因, 可以 urlquote 转一下文件名 |
8 Erroad Sep 16, 2020 .xls Microsoft Excel application/vnd.ms-excel .xlsx Microsoft Excel (OpenXML) application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
9 renmu123 Sep 16, 2020 via Android 你用 requests 求理一下文件看 |
10 Erroad Sep 16, 2020 这是用 google 搜到的 mdn 对 xls,slsx mime 类型的描述,但是怀疑也可能不是这个原因? |
11 hushao Sep 17, 2020 via iPhone 你用 postman 看二进制文件当然是乱码... |
12 vegetableChick Sep 22, 2020 postman 不是可以直接 post_and_save 么? |
13 dwadewyp OP @vegetableChick 已解决 |