IE6无法正常下载文件的BUG
针对IE6下,如果是通过服务器的请求资源来下载获得目标文件,可能会遇到“Internet Explorer 不能下载文件”的错误信息,这里仅仅笔记下解决办法。
官方的解释说明,需要补丁修复
http://support.microsoft.com/kb/816868/zh-cn
可以加入以下的Response头信息即可
self.req.set_header("Cache-Control", "must-revalidate, post-check=0, pre-check=0")
完整的python代码片段如下:
def _generate_download(self, file_name, content): self.req.set_header("Content-Type", "application/octet-stream;charset=utf-8") if self._is_IE_browser(): self.req.set_header("Cache-Control", "must-revalidate, post-check=0, pre-check=0") self.req.set_header("Content-Disposition", "attachment; %s" % urllib.urlencode({"filename":file_name})) else: self.req.set_header("Content-Disposition", "attachment; filename=\"" + file_name + "\"") return self.req.write(content) def _is_IE_browser(self): """ The download operation with chinese encoding, different browsers require different processings """ user_agent = (self.req.environ["HTTP_USER_AGENT"]).lower() return "msie" in user_agent