Non-ascii passwords
Michael Ströder
michael at stroeder.com
Fri Aug 27 14:30:05 CEST 2010
Marc Brevoort wrote:
> I've inherited a little authentication module which uses
> python-ldap (v1.92, 2005/11/03). For the most of it, it works
> fine, but when a user has decided to use non-ascii characters
> in their password, they will be blocked access and the
> authentication log shows a message such as:
>
> 2010-08-27 11:02:50,398 DEBUG Exception: 'ascii' codec can't encode
> character u'\xdf' in position 5: ordinal not in range(128)
I'm not sure which component write this message.
But python-ldap expects all values to be raw strings. So the calling
application is responsible for converting Unicode objects to raw strings with
the appropriate encoding. In case of LDAPv3 this is UTF-8.
> - It should be possible to work around the issue by escaping the
> non-ascii characters in the password, replacing them with a backslash
Please try to understand first how the Python syntax representation of Unicode
and raw strings is which displayed in the message above.
http://docs.python.org/reference/lexical_analysis.html#string-literals
There's no need to mess with the back-slashes at all. Simply fix the calling
application to do the right thing. Probably calling password.encode('utf-8')
will do.
Ciao, Michael.
More information about the python-ldap
mailing list