How to change character encoding of form fields to UTF-8 ? #8137
Replies: 4 comments
-
This is hardcoded in Starlette: https://github.com/encode/starlette/blob/master/starlette/formparsers.py#L101 It should be fixed there, I haven't had the time to try and fix it. There's a related issue: encode/starlette#425 |
Beta Was this translation helpful? Give feedback.
-
encode/starlette#425 just has been closed and the fix has been released as 0.12.5. |
Beta Was this translation helpful? Give feedback.
-
The latest versions of FastAPI use newer versions of Starlette, so the fix should be already there 🎉 |
Beta Was this translation helpful? Give feedback.
-
I confirm that with FastAPI 0.48.0, the above test case works as expected. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I tried to build a form specifying a character set like this :
A meta tag in the HTML page header specify an UTF-8 charset (
<meta charset="utf-8"/>
) and the page display properly in Safari including the button. I can enter accentuated characters in the aField.The corresponding python handler is :
Whatever I specify, the field content and the value of the button used is always transfered as a string (as specified in the parameters) but Latin-1 encoded despite the whole html page and the form specifying UTF-8.
I known that HTTP 1.1 specification includes default Latin-1 encoding but I thought it could be altered by the meta tag and explicit character set settings.
It is not a blocking issue as converting fields content is not complex but, for performance reasons, and error prevention, I was wondering wether there would be a better option to get fields content in UTF-8 strings directly eliminating the need for conversion.
Many thanks for you great work and your active support to community !
Beta Was this translation helpful? Give feedback.
All reactions