Closed louiz closed 12 years ago
Hi, i can see that you are messing up with your encodings here. If you are using non-ascii URLs, make sure to decode those characters using a suitable encoding. For example, your example works with a small change(using utf-8 encoding);
@app.route("/%s/" % "♥".decode('utf-8'))
def heart():
return 'it works'
I am really not sure if this is something flask must incorporate or not.
If you use unicode strings properly it works out of the box:
@app.route(u"/♥")
def heart():
return "It works!"
Hm, actually you’re right, it works perfectly as is. I don’t know what I missed when I first tested this. Sorry about the noise.
Looking forward to a release of flask for Python 3.
@xyproto Surprise! Flask is already available on Python3. Just pip install flask
@gioi Perfect, I'll package it for Arch Linux then. (I could see no hints of the Python 3 version being released on the flask webpage).
Ok, moved. "python-flask" is now the official Python 3 package for Arch Linux. The "setup.py test" checks fails for werkzeug for python3, though, but I'm sure you had that in mind when you made the recommendation. Thanks, gioi!
Thank you, @xyproto. Would you please check that mitsuhiko/werkzeug#426 corresponds to the failing test?
Sure. It seems to be a different test that fails:
test_shared_data_middleware (werkzeug.testsuite.wsgi.WSGIUtilsTestCase) ... ERROR
test_shareddatamiddleware_get_file_loader (werkzeug.testsuite.wsgi.WSGIUtilsTestCase) ... ok
======================================================================
ERROR: test_shared_data_middleware (werkzeug.testsuite.wsgi.WSGIUtilsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/build/python-werkzeug/src/python-werkzeug-0.9.1/werkzeug/testsuite/wsgi.py", line 36, in test_shared_data_middleware
with open(path.join(test_dir, to_native(u'\xe4\xf6\xfc', 'utf-8')), 'w') as test_file:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 15-17: ordinal not in range(128)
----------------------------------------------------------------------
Ran 317 tests in 1.662s
FAILED (errors=1)
Argh, horrible news. You should report it as a bug, in the meantime I'll try to reproduce this.
@gioi I've already tried to install Flask for Python but it never seems available, and it does install flask for python2, it seems pip is for python2. I'm on Arch and Ubuntu I also checked in repositories but python3-flask doesn't exist.
@gio Will do.
@DarkRedman: if you're on Arch, just install "python-flask" (not "python3-flask", python 3 is the default python on Arch and thus only called "python")
I just tried this in Python 3 and it gave me a 404 for a unicode route; is this a bug or am I just doing something wrong?
Try this simple routing function:
@app.route(u'/♥/') def heart(): return "It works"
Or @app.route('/%E2%99%A5/') def heart(): return "It works"
Trying to GET /%E2%99%A5/ HTTP/1.1 (which is what a browser does when trying to reach http://example.com/♥/)
You get a 404 not found in return.
I could not found anything in the doc talking about that, so I assume it’s a bug.