Pylons/pyramid — Issue #352: UnicodeEncodeError when using traversal and url is quoted 
Author: mrdobrzanski
Created: 2011-11-15 11:32:12+00:00
State: open

A quoted URL like http://localhost:6543/CustomerID/%C4%84%C5%81%C3%93$! causes this error:

File "/home/mikado/mydevenv/env/lib/python2.6/site-packages/pyramid-1.2.1-py2.6.egg/pyramid/traversal.py", line 478, in traversal_path
path = path.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 20-22: ordinal not in range(128)

I've found that path is unquoted in httpserver.py line 180 - WSGIHandlerMixin.wsgi_setup() from that moment environ['PATH_INFO'] is unquoted. Traversal docs says "Each segment is URL-unquoted, and subsequently decoded
into Unicode. Each segment is assumed to be encoded using the UTF-8 encoding (or a subset, such as ASCII)".
Well, it's only unquoted and not encoded to utf-8.

In my patch I just force to encode('utf-8') instead 'ascii' in traversal.py traversal_path() but I'm not sure if that's a right way of doing it.