The gecos attribute type must be asked to LDAP server, and according to this type the gecos string value must be fill in.
This way the gecos attribute can be set using the classic nis.schema
(IA5 string) or the schema needed in CJK case (UTF-8 string).
Here is a code snippet to ask the LDAP server for the gecos attribute type:
import ldap.schema
ssse, schema = ldap.schema.urlfetch("ldap://127.0.0.1")
sa = schema.get_obj(ldap.schema.AttributeType, "gecos")
print sa.syntax
This code will return the gecos attribute SYNTAX string, e.g.:
1.3.6.1.4.1.1466.115.121.1.26