Python龙卷风编码异常(Python tornado encoding exception)

编程入门 行业动态 更新时间:2024-10-26 17:23:49
Python龙卷风编码异常(Python tornado encoding exception)

我通过@ 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=""))

更多推荐

本文发布于:2023-07-31 02:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340394.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:龙卷风   异常   Python   exception   encoding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!