I stumbled upon a strange Unicode URL encoding problem in Flask.
@app.route("/it2/<string:name>")
def render_it2(name=""):
name = _fix_encoding(name)
return _render_file("it2", name)
When name contains Unicode characters,
they are decoded as iso-8859-1
instead of utf-8.
So I had to add the _fix_encoding function:
def _fix_encoding(string):
return string.encode('iso-8859-1').decode('utf8')
I understand that it is dirty hack, that's why I would like to ask Flask/Werkzeug gurus, what is wrong with my setup? What should I change in order to get URLs decoded in UTF-8 already, so that this ugly re-encoding would be not needed?
There are a lot of similar questions/answers on SO, but no responses that could be really helpful, e.g.:
I suppose that there should be some environment varialbe, or some configuration option that influences default Flask encoding.
I have the following LANG/LC_* on that host:
$ echo $LANG
en_US.UTF-8
$ export | grep LC
declare -x LC_ADDRESS="en_US.UTF-8"
declare -x LC_IDENTIFICATION="en_US.UTF-8"
declare -x LC_MEASUREMENT="en_US.UTF-8"
declare -x LC_MONETARY="en_US.UTF-8"
declare -x LC_NAME="en_US.UTF-8"
declare -x LC_NUMERIC="en_US.UTF-8"
declare -x LC_PAPER="en_US.UTF-8"
declare -x LC_TELEPHONE="en_US.UTF-8"
declare -x LC_TIME="en_US.UTF-8"
No iso-8859-1 whatsoever. Where does it come from?