Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response headers support custom encoding #790

Closed
0b1Kenobi opened this issue Jan 13, 2020 · 1 comment · Fixed by #792
Closed

response headers support custom encoding #790

0b1Kenobi opened this issue Jan 13, 2020 · 1 comment · Fixed by #792

Comments

@0b1Kenobi
Copy link

Hi~ When i try to return a FileResponse with Chinese filename, i got such error:

UnicodeEncodeError: 'latin-1' codec can't encode character '\u6708' in position 32: ordinal not in range(256)

Then i found all header items will be encode with latin-1, after i change it manually to utf-8, my problem was solved.

e.g.

  • responses.Response.init_headers, line 63
raw_headers = [
    (k.lower().encode("latin-1"), v.encode("latin-1"))
    for k, v in headers.items()
]

So may be it should encode with self.charset or give a custom parameter so that i can choose encoding to utf-8?

Thx for the great project~

@CyberQin
Copy link

CyberQin commented Aug 3, 2020

#792 only solves FileReponse,but it still a problem in streamreponse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants