Ticket #2453 (closed defect: worksforme)
Error when logging out with non-ascii user name
| Reported by: | chrisz | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 2.1rc1 |
| Component: | TurboGears | Version: | trunk |
| Severity: | blocker | Keywords: | |
| Cc: |
Description
After some patches for #2438 it is now possible to log in with a non-ascii username. However, when I try to log out, I get exceptions like this one:
URL: http://localhost:8080/logout_handler File '.../weberror-0.10.1-py2.6.egg/weberror/evalexception.py', line 431 in respond app_iter = self.application(environ, detect_start_response) File '.../tg-dev/tg/configuration.py', line 760 in remover return app(environ, start_response) File '.../repoze.tm2-1.0a5-py2.6.egg/repoze/tm/__init__.py', line 23 in __call__ result = self.application(environ, save_status_and_headers) File '.../repoze.who-1.0.18-py2.6.egg/repoze/who/middleware.py', line 133 in __call__ app_iter = challenge_app(environ, start_response) File '.../paste/httpexceptions.py', line 269 in wsgi_application headers, content = self.prepare_content(environ) File '.../paste/trunk/paste/httpexceptions.py', line 244 in prepare_content content = self.html(environ) File '.../paste/trunk/paste/httpexceptions.py', line 229 in html body = self.make_body(environ, self.template, html_quote, no_quote) File '.../paste/trunk/paste/httpexceptions.py', line 205 in make_body args[k] = escfunc(v) File '.../paste/trunk/paste/util/quoting.py', line 37 in html_quote return cgi.escape(unicode(v).encode(encoding), 1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 330: ordinal not in range(128)
This seems to be caused by Paste trying to get a unicode representation of a webob.Request which has utf-8 chars in it. Unfortunately, Paste cannot deal with such requests (see here).
In this case, the utf-8 char is in the cookie set by repoze.what.authtkt which includes the utf-8 encoded user name in the 'authtkt' cookie. (Maybe repoze.what.authtkt should better convert the cookie to a pure 7-bit representation like the standard Python Cookie lib does?)
The reason why Paste tries to get a representation of the request seems to have something to do with the add_dbsession_remover_middleware method in turbogears.configuration.
Replying to chrisz:
Just a quick correction: It's a repoze.who built-in plugin (auth_tkt) the one in charge of that. ;-)