[python-win32] Translating vbs GetObject("LDAP://...") to Python?

R. Alan Monroe amonroe at columbus.rr.com
Mon Nov 8 15:09:10 CET 2004


What is the Python equivalent of this vbs two liner?

set obj = GetObject("LDAP://cn=johndoe, ou=General Users, ou=Accounts, dc=na, dc=nisource, dc=net")
wscript.echo obj.Get("description")


I tried cobbling together this by looking at various google searches,
but it doesn't work:

import win32com.client
adsi = win32com.client.Dispatch('ADsNameSpaces')
ldap = adsi.GetObject("", "LDAP:")
ds = ldap.OpenDSObject("LDAP://cn=johndoe, ou=General Users, ou=Accounts, dc=na, dc=nisource, dc=net", '', '', 0)
desc = ds.Get("description")
print desc

The error I get:
Traceback (most recent call last):
  File "ldapcomtest.py", line 11, in ?
    ds = ldap.OpenDSObject("LDAP://cn=U118919, ou=General Users, ou=Accounts, dc=na, dc=nisource, dc=net", '', '', 0)
  File "<COMObject <unknown>>", line 2, in OpenDSObject
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147016672), None)

(Line 11 in the actual program is the ds = ldap.Open... line)



More information about the Python-win32 mailing list