作者jcjan (None)
看板Python
標題[問題] django 下載 pdf
時間Wed Mar 28 16:31:31 2018
用django寫了一個網站,
需讓遠端下載pdf檔,
程式碼如下
def download(request):
with open('f:/test.pdf','r') as f:
response=HttpResponse(f.read(),content_type='application/pdf')
response['Content-Disposition'] = 'attachment;filename=test.pdf'
在f.read()發生錯誤,
'cp950' codec can't decode byte 0x9c in position 519: illegal multibyte
sequence
我用FileWrapper(f)取代f.read()依舊得到相同訊息,
請高手相助!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.26.199
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1522225894.A.6E2.html
→ OGCKM: open file 改參數成rb, r是開文字檔用的 03/28 16:56
→ jcjan: 感恩!! 03/28 17:05