Ryan Felder
rfelder at globaltecsolutions.com
Tue Feb 10 09:41:40 EST 2004
Sorry for not including my version numbers. Apache/2.0.43 (Win32) mod_ssl/2.0.43 OpenSSL/0.9.6h mod_python/3.0.4 Python/2.3.3 I am using the most recent version of python from python.org, and the win32all that is included with it. My version of apache is from the swamp distribution of apache for windows. I have done another example to verify that this is not an issue with the third party dll I am calling. The example code is very similar to my previous example code. This code properly opens up excel from a command prompt, but when run from under mod_python, it seems to ignore the com calls entirely. This code will return "aha" to my web browser, as expected. def index(): import win32com.client a=win32com.client.Dispatch('Excel.Application') a.Visible = 1 a.Workbooks.Add() a.ActiveSheet.Cells(1,1).Value = 'aha' return "aha" if __name__ == "__main__": print index() Thanks again. - Ryan -----Original Message----- From: David Fraser [mailto:davidf at sjsoft.com] Sent: Tuesday, February 10, 2004 1:04 AM To: Ryan Felder Cc: mod_python at modpython.org Subject: Re: [mod_python] Mod_Python and win32com This sounds wierd We use win32com.client without any problems from within mod_python (also using similar versions to you, but Python 2.2). Which version of win32all are you using? It may be interesting to try stepping into the win32com code and adding traces, to see whether the COM call is actually made and nothing is returned, or whether it never gets there and isn't producing an error though it should be. David Ryan Felder wrote: >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 > >
|