[python-win32] unicode breaks win32com?

Preston Landers planders at gmail.com
Thu Oct 4 00:17:20 CEST 2012


This is probably not the "correct" answer, but you can see if it helps. At
the top of your script try adding this:

import sys
sys.setdefaultencoding("utf-8")


On Wed, Oct 3, 2012 at 4:50 PM, Matt LaPlante <mattl at google.com> wrote:

> 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?
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20121003/20fddc8e/attachment.html>


More information about the python-win32 mailing list