How do I convert a unicode header to byte string in Flask?
how bout
bytes(whatever_unicode.encode("utf-8"))
or per J.F. Sebastians comment
some_unicode.encode("ISO-8859-1")
or perhaps
import urlliburllib.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_requestdef 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
it's working!
file = request.files.get('fileupload')file = StringIO(file.read().decode("ISO-8859-1"))