我通过@ tornado.web.stream_request_body装饰器接收文件并保存。 但是如果我尝试下载一个文件,我会收到异常:
'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“某些数据[this part]”)也许这就是为什么会发生错误? 如何解决它?
I receive files by @tornado.web.stream_request_body decorator and save it. But with one file if I try to download it, i receive exception:
'latin-1' codec can't encode characters in position 42-47: ordinal not in range(256)
in line self.flush() of tornado handler.
I see that data contain part as a \x00word/_rels/document.xml.relsPK\x01\x02-\ (b"some data [this part]") Maybe that's why an error occurs? How to fix it?
最满意答案
我解决了问题。 在Content-Disposition头文件中的urlencode名称:
self.set_header('Content-Disposition', 'attachment; filename=' + urllib.parse.quote(file_name, safe=""))I fix problem. urlencode name of file in Content-Disposition header:
self.set_header('Content-Disposition', 'attachment; filename=' + urllib.parse.quote(file_name, safe=""))更多推荐
发布评论