[mod_python] Mod_Python and win32com

Ryan Felder rfelder at globaltecsolutions.com
Mon Feb 9 15:40:13 EST 2004


Hi all, I'm pretty new to working with Mod_Python, and the project I am
working on requires me to be able to poll for some data through COM.

I am developing in windows 2000 professional, and will be running
my code on windows apache 2.0 with mod python. More specifically,
I am using the distribution of apache ssl and others named Swamp.

The code works fine when I run it standalone, however, when I attempt
to run it on my development site, the calls to the com object that work
beautifully alone, simply fail to return data. As follows is a brief
code sample which demonstrates this behaviour. This code functions
properly from a command prompt or in the interpreter.

def index():
	import win32com.client
	a=win32com.client.Dispatch('MyDataSource')
	b=str(a.GetOrders(account_identifier,'',2,0))
	return str(len(b))

if __name__ == "__main__":
	print index()

When this code runs standalone, it will return a non-zero value,
and when run from mod_python, it returns a zero value, due to
the len() function measuring the length of the output of my data call.

By way of typos, I have been able to produce exceptions in my testing
browser, so this leads me to believe that it is not passing any exceptions.

My research online has suggested that I try importing my modules through
apache.import_module. This gives me a number of different issues where
if I instantiate an instance of win32com, then try to address
that.client.Dispatch,
I recieve "module does not have 'client'", or similarly, if I try to
instantiate
an instance of win32com.client, I recieve "module does not have 'Dispatch'".

I have also seen it suggested that I initialize the com properly, and
manually,
by
	import sys
	sys.coinit_flags = 0

as well as

	import pythoncom
	pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)

which I do before attemting to import win32com, but to no avail,
in many, and in all permutations.

I have tried every permutation of apache.import_module and import,
that I can muster, and I am hitting a brick wall.

It seems that there is a breakdown in communications between myself and the
com objects when I try to import them. Any help that you all can offer me
would be hugely appreciated!

- Ryan




More information about the Mod_python mailing list