Ticket #194 (defect)
Opened 3 years ago
Last modified 3 years ago
error using win32com.client.GetObject with Rev 346
Status: closed (fixed)
| Reported by: | christian@dowski.com | Assigned to: | rdelon |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | CherryPy code | Keywords: | pywin32 |
| Cc: |
I have some code that worked fine in CP 2.0 but raises an exception in the rev 346 trunk code. It uses the win32com.client module from the pywin32 project.
Here is the code that will throw the exception:
from win32com.client import GetObject class Test: @cpg.expose def getLastLogins(self, ouDN=None): """ This report scours the OU passed as an argument and displays a table of users and their last login date and time. """ if ouDN == None: yield "You need to supply an OU" raise StopIteration #here is where we get our exception ou = GetObject('LDAP://' + ouDN) #remaining code omitted cpg.root=Test() cpg.server.start()
and here is the traceback:
Traceback (most recent call last):
File "c:\python24\Lib\site-packages\cherrypy\_cphttptools.py", line 166, in run
applyFilters('beforeFinalize')
File "c:\python24\Lib\site-packages\cherrypy\_cphttptools.py", line 414, in applyFilters
method()
File "c:\python24\lib\site-packages\cherrypy\lib\filter\logdebuginfofilter.py", line 57, in beforeFinalize
body = ''.join(cpg.response.body)
File "c:\python24\Lib\site-packages\cherrypy\_cphttptools.py", line 425, in flattener
for x in input:
File "server.py", line 84, in getLastLogins
ou = GetObject('LDAP://' + ouDN)
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 am guessing this is a CP issue and not a pywin32 issue since it works ok in 2.0.
Change History
06/20/05 16:42:01: Modified by fumanchu
06/21/05 08:58:10: Modified by christian@dowski.com
Here is the output from "yield repr(ouDN)":
'OU=StudentTemp?, DC=greenville, DC=edu'
I also checked "type(ouDN)" and got <type 'str'>.
I also tested the code in "production" mode and got a similar traceback (minus the logdebuginfofilter bit). Any other debugging suggestions?
06/22/05 02:31:38: Modified by fumanchu
WAG: are spaces allowed between attributes in an LDAP URL?
06/22/05 02:35:01: Modified by fumanchu
Also, don't you need "LDAP:///" (3 "/" characters in a row) if you don't provide a host+port?
06/22/05 09:19:30: Modified by christian@dowski.com
WAG: are spaces allowed between attributes in an LDAP URL?
Yeah, spaces are ok.
Also, don't you need "LDAP:///" (3 "/" characters in a row) if you don't provide a host+port?
Nope. At least not in the land of Microsoft's ADSI LDAP provider (rules of the known universe do not apply).
I did a little more testing. I didn't bother with passing in the ouDN, and passed the GetObject() function a string literal ('LDAP://OU=SomeOU, DC=mysite, DC=com') right in the code, and it still failed. Again, if I switch over to CP 2.0, it works fine. Bizarre.
I also changed the method so that it isn't a generator. Here is the traceback:
Traceback (most recent call last):
File "c:\python24\lib\site-packages\cherrypy\_cphttptools.py", line 164, in run
main()
File "c:\python24\lib\site-packages\cherrypy\_cphttptools.py", line 319, in main
body = func(*(virtualPathList + cpg.request.paramList),
File "server.py", line 86, in getLastLogins
ou = GetObject('LDAP://' + ouDN)
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)
06/22/05 11:17:03: Modified by fumanchu
Hm! The next thing I would do:
Bypass your browser and the CP HTTP servers and see what happens. Change cpg.server.start() to cpg.server.start(initOnly=True), then request the page like this:
from cherrypy import cpg from cherrypy.test import helper helper.request("/getLastLogins?ouDN=OU=StudentTemp?,+DC=greenville,+DC=edu") print "status>", cpg.response.status print "headers>", cpg.response.headers print "body>", cpg.response.body
If you don't get a traceback in cpg.response.body (i.e. the GetObject? call works at that point), then there's probably something wrong with threading in the server you're using. Perhaps the "clsctx" is thread-dependent, or you're missing a pythoncom.CoInitialize() or ...?
Anyway, I figure the problem must be in the server, since nothing else (between your code and the server) should have any effect on COM calls--almost everything in-between is just string manipulation when you get right down to it.
06/22/05 14:15:36: Modified by christian@dowski.com
Looks like you nailed it - no errors, test went fine.
I added calls to CoInitialize() and CoUninitialize() in cpg.server.on(Start|Stop)ThreadList and the code works like a charm now.
Thanks for your help and sorry to waste your time on a non-CP bug.
06/22/05 15:54:23: Modified by fumanchu
- status changed from new to closed.
- resolution set to fixed.


To help us debug this, please replace the GetObject? call (and any remaining code) with "yield repr(ouDN)", and tell us the result. My guess is that ouDN contains unescaped unicode or unescaped slashes.