[python-ldap] GECOS and UTF-8

Ville Törhönen ville at torhonen.fi
Mon Apr 11 15:14:59 CEST 2011


I've created a user management script with python-ldap and I'm having
difficulties with accented characters such as "ä" or "ö", specifically
in the GECOS field. This appears to work with cn.

>>> a = "ä"
>>> b = "ö"
>>> gecos = a + b
>>> gecos

Now 'gecos' is a UTF-8 encoded string. If I then use it in a modlist and try
to add the modlist into OpenLDAP, I get a traceback saying:

ldap.INVALID_SYNTAX: {'info': 'gecos: value #0 invalid per syntax',
'desc': 'Invalid syntax'}

If I try to add it as Unicode (gecos = gecos.decode('utf-8')), I get a
traceback saying:

TypeError: ('expected a string in the list', u'\xe4\xf6')

Is there a solution for this? At the moment I have to modify the GECOS field
manually by using Apache Directory Studio.

Ville Törhönen

More information about the python-ldap mailing list