CherryPy not playing nicely with win32com?
infidel
saint.infidel at gmail.com
Thu Nov 10 17:34:41 EST 2005
I've been trying to get my CherryPy server to authenticate users
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_AUTHENTICATION = 1
def login_valid(username, password):
ldap = GetObject("LDAP:")
try:
ldap.OpenDSObject(
'LDAP://XXXXXXXX.US',
'XXXXXXXX\\' + username,
password,
ADS_SECURE_AUTHENTICATION
)
return True
except:
return False
This function works great if I call it from the interactive prompt:
>>> import ldap
>>> ldap.login_valid('mylogin', 'XXXXXXXX') # pass incorrect network password
False
>>> ldap.login_valid('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\Lib\site-packages\cherrypy\_cphttptools.py", line
77, in _run
applyFilters('beforeMain')
File "C:\Python24\Lib\site-packages\cherrypy\_cphttptools.py", line
461, in applyFilters
method()
File "filters\authenticate.py", line 29, in beforeMain
if ldap.login_valid(username, password):
File "K:\src\py\XXXXXXXX\filters\ldap.py", line 6, in login_valid
ldap = GetObject("LDAP:")
File "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
line 73, in GetObject
return Moniker(Pathname, clsctx)
File "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
line 88, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
com_error: (-2147221020, 'Invalid syntax', None, None)
I don't get it. How can it be ok at the >>> prompt but invalid under
CherryPy?
More information about the Python-list
mailing list