2017-01-22 42 views
0

我通過@ tornado.web.stream_request_body裝飾器接收文件並保存。 但有一個文件,如果我嘗試下載它,我得到異常:Python龍捲風編碼異常

'latin-1' codec can't encode characters in position 42-47: ordinal not in range(256)

在龍捲風處理程序的行 self.flush()

我看到數據包含部分爲\x00word/_rels/document.xml.relsPK\x01\x02-\(b「some data [this part]」) 也許這就是錯誤發生的原因?如何解決它?

回答

0

我修復了問題。 urlencode在Content-Disposition標題中的文件名稱:

self.set_header('Content-Disposition', 
    'attachment; filename=' + urllib.parse.quote(file_name, safe=""))