我正在尝试将 Flask 响应对象中的 Content-Disposition header 设置为可能包含瑞典字符 (åäö) 的文件名。我的测试代码如下所示:
response = flask.send_file(output_file_path)
response.headers[u"Content-Disposition"] = u'filename="åäö.pdf"'
这会出现以下错误:
File "C:\Python27\Lib\BaseHTTPServer.py", line 401, in send_header
self.wfile.write("%s: %s\r\n" % (keyword, value))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 10: ordinal
not in range(128)
我已经尝试了编码、解码和几乎任何我能想到的方法,但我就是无法让 Flask 接受我想在我的 header 中使用 Unicode (utf-8)!
最佳答案
关于python - Flask 内容配置 header 中的 Unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13450049/