[python-win32] unicode breaks win32com?

Matt LaPlante mattl at google.com
Wed Oct 3 23:50:06 CEST 2012


I'm using win32com to query AD for the adsPath as below.  It's come to my
attention that a user with unicode is apparently breaking this.

user = 'mrunicode'
dnc =
win32com.adsi.ADsGetObject('LDAP://rootDSE').Get('DefaultNamingContext')
ado = win32com.client.Dispatch('ADODB.Connection')
ado.Open('Provider=ADsDSOObject')
lfilter = '(&(sAMAccountName=%s)(objectCategory=User))' % user
search = '<LDAP://%s>;%s;adsPath;subtree' % (dnc, lfilter)
obj_record = ado.Execute(search)[0]
print obj_record.Fields('adsPath'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python_26\files\lib\site-packages\win32com\client\dynamic.py",
line 201, in __str__
    return str(self.__call__())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
position 11: ordinal not in range(128)

Is there a workaround for this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20121003/96e1054a/attachment.html>


More information about the python-win32 mailing list