How do I convert a unicode header to byte string in Flask?

戏子无情 提交于 2019-12-05 21:48:18

how bout

bytes(whatever_unicode.encode("utf-8"))

or per J.F. Sebastians comment

some_unicode.encode("ISO-8859-1")

or perhaps

import urllib
urllib.quote(unicode_string)

one of those should work ... I think

I got stuck on this for a long time. I am not at all satisfied with the selected answer. Here's what I have working in production

@app.after_request
def after(response):
    new_resp_headers = {}
    for k, v in response.headers.items():
        new_resp_headers[k.encode('ISO-8859-1')] = v.encode('ISO-8859-1')
    response.headers = new_resp_headers
    return response
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!