python - Flask 内容配置 header 中的 Unicode

标签 python http unicode flask

我正在尝试将 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)!

最佳答案

参见 RFC 6266用于内容处置和 5987用于编码。测试用例 here .

关于python - Flask 内容配置 header 中的 Unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13450049/

相关文章:

python - 异常 : Version mismatch:cffi

cocoa - 这是来自 iPad 的格式错误的 http 请求吗?它会杀死 Node.js 多部分解析器

arrays - Python如何将带有西里尔符号的字典保存到json文件中

java - antlr3 unicode字符导致错误

python - 在字典列表中复制字典对(键,值)并尊重顺序的有效方法

python - Python 中的 cvCalcEigenObjects 和 cvEigenDecomposite

python xlwt : preserve all styles but one

php - drupal_http_request 在 drupal 6 上没有代理支持......想法怎么做?

http - 您如何知道 HTTP 压缩是否有效?

c++ - 如何声明 wchar_t 并稍后设置其字符串值?