473,668 Members | 2,639 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_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?

Nov 10 '05 #1
2 2124
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.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?


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.CoIni tialize() and pythoncom.CoUni nitialize() 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.CoIni tialize() and pythoncom.CoUni nitialize() 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
7003
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 and Word examples run fine. win32com.client.Dispatch("Excel.Application") etc., but how does one know the ("<foo>.<bar>") to type in? Excel looks only vaguely like "Excel.Application" in the com browser.
0
1323
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 cherrypy.org site now has a nice forum and a wiki - Sessions are now fully thread-safe and they work great in production environments with the thread-pool HTTP-server
13
3513
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. I played around with some, and I have reduced my choices to two very different frameworks: cherrypy+cheetah and twisted+nevow. I am writing the prototype in cherrypy with cheetah, and I like it very much. I am very impressed with the speed of...
2
4259
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? In cherrypy 2.0 & python 2.4 -- Best Regards, Wang Kebo
2
7060
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 now I can't _use_ win32com as a normal user, because normal users can't write there: PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond@skippinet.com.au) -
0
1153
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 will eventually require the python code to call stored procedures in a database which means I'll need to run CherryPy with a threadPool so individual database calls don't block the whole server. I'm not to that point yet, I'm just getting a...
1
2272
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 SystemExit raised: shutting down autoreloader 2005/10/19 12:42:33 HTTP INFO CherryPy shut down 2005/10/19 12:42:34 CONFIG INFO Server parameters: 2005/10/19 12:42:34 HTTP INFO SystemExit raised: shutting down autoreloader
10
4941
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 mod_python vs. building an application server using Python-based tools like CherryPy, Quixote, Draco, etc.? Thanks.
2
7632
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 running Apache, that I don't have root access to. I will be publishing the html/image/python files in a directory off of my current web page, and running the app as a user on the system. I'd like to be able to specify the base url for the app,...
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8797
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8656
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2791
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 we have to send another system
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.