against our network. I've managed to cobble together a simple function
that uses our LDAP server to validate the username and password entered
by the user:
# ldap.py
from win32com.client import GetObject
ADS_SECURE_AUTH ENTICATION = 1
def login_valid(use rname, password):
ldap = GetObject("LDAP :")
try:
ldap.OpenDSObje ct(
'LDAP://XXXXXXXX.US',
'XXXXXXXX\\' + username,
password,
ADS_SECURE_AUTH ENTICATION
)
return True
except:
return False
This function works great if I call it from the interactive prompt:
import ldap
ldap.login_vali d('mylogin', 'XXXXXXXX') # pass incorrect network password False ldap.login_vali d('mylogin', 'XXXXXXXX') # pass correct network password
True
But as soon as I have my CherryPy filter call this exact same function,
I get an "invalid syntax" COM error:
Traceback (most recent call last):
File "C:\Python24\Li b\site-packages\cherry py\_cphttptools .py", line
77, in _run
applyFilters('b eforeMain')
File "C:\Python24\Li b\site-packages\cherry py\_cphttptools .py", line
461, in applyFilters
method()
File "filters\authen ticate.py", line 29, in beforeMain
if ldap.login_vali d(username, password):
File "K:\src\py\XXXX XXXX\filters\ld ap.py", line 6, in login_valid
ldap = GetObject("LDAP :")
File "C:\Python24\Li b\site-packages\win32c om\client\__ini t__.py",
line 73, in GetObject
return Moniker(Pathnam e, clsctx)
File "C:\Python24\Li b\site-packages\win32c om\client\__ini t__.py",
line 88, in Moniker
moniker, i, bindCtx = pythoncom.MkPar seDisplayName(P athname)
com_error: (-2147221020, 'Invalid syntax', None, None)
I don't get it. How can it be ok at the >>> prompt but invalid under
CherryPy?