473,509 Members | 3,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CherryPy not playing nicely with win32com?

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?

Nov 10 '05 #1
2 2113
infidel wrote:
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:
[...]
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?


Just an idea: because in CherryPy it is running in multithreading mode?
If you are using threads together with COM stuff, you will have to
add pythoncom.CoInitialize() and pythoncom.CoUninitialize() calls
in your code -- for each thread.

--Irmen
Nov 11 '05 #2
> Just an idea: because in CherryPy it is running in multithreading mode?
If you are using threads together with COM stuff, you will have to
add pythoncom.CoInitialize() and pythoncom.CoUninitialize() calls
in your code -- for each thread.


That worked perfectly. Thanks a million!

I used to hate COM just because of our huge VB project. Now I can hate
it for this too!

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6982
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
0
1317
by: Remi Delon | last post by:
Hello everyone, I am pleased to announce the release of CherryPy-10. It's been a while since I last announced a CherryPy release on this newsgroup but a lot has happened since then: - The...
13
3500
by: Charlotte | last post by:
I am developing a web application and am looking for the best framework to do this in. I know this is an old question, and I have read the list archives and a couple of comparison pages on the web....
2
4247
by: mep | last post by:
Hi, After lookup in cherrypy site and google for a while, I haven't found any information about cherrypy how to serve dynamic binary file(some generated charts).Is there any easy way to do this?...
2
7015
by: Sibylle Koczian | last post by:
Hello, I've installed Python 2.4 and the win32 extensions, using administrator rights, under Windows XP in "C:\Programme". As this is a directory without spaces I didn't expect any problems. But...
0
1150
by: infidel | last post by:
I have just recently discovered CherryPy and Kid (many kudos to the respective developers!) and am tinkering with them to see what I can come up with. The application I eventually want to write...
1
2267
by: infidel | last post by:
I did an "svn update" of cherrypy this morning, and now when I try running a server, the log window just keeps reporting the autoreloader restarting over and over: 2005/10/19 12:42:33 HTTP INFO...
10
4917
by: Vincent Delporte | last post by:
Hi I'm still a newbie when it comes to web applications, so would like some help in choosing a solution to write apps with Python: What's the difference between using running it through...
2
7626
by: Brian Blais | last post by:
Hello, I'd like to start trying out some cherrypy apps, but I've been having some setup problems. I think I need some bone-head simple example to clear my understanding. :) I'm on a system...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.