我試圖將Flask響應對象中的Content-Disposition標題設置爲可能包含瑞典字符的文件(åäö)。我的測試代碼如下所示:Flask內容處置標題中的Unicode
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)
我已經試過編碼,解碼和幾乎任何我能想到的,但我就是不能讓燒瓶接受我想在我的頭文件中使用Unicode(utf-8)!
該鏈接提到ISO 8859-1是好的,因爲我的角色在ISO 8859-1中,我可以用它來代替嗎? – monoceres
@monoceres在「ISO 8859-1」中對字符串進行編碼並試用。最有可能它應該工作得很好。 – Ifthikhan
不,ISO-8859-1不能可靠工作;某些UA默認爲其他內容(UTF-8,引用頁面的頁面編碼或系統區域設置)。 –