win32com代码在Python Web服务器上运行,但在Apache服务器上运行

时间:2015-01-17 21:50:06

标签: python apache cgi win32com

我正在使用Python并使用win32com库来建立ADODB连接或写入文件或发送Outlook消息。 问题是当我在内置的Python网络服务器上托管它时代码工作正常但是当我在Apache webserver上托管它时会抛出错误 以下是抛出错误的代码:

169     conn = win32com.client.Dispatch(r'ADODB.Connection') # Making an ADODB connection 
170     conn.CommandTimeout = 7200 # To set the time out time of the connection 
171     DSN = "Data Source=DDSP; Database=DDSP; Persist Security Info=True; User ID=" + TDUserName + "; Password=" + TDPassword + "; Session Mode=ANSI;"
conn undefined, global win32com = <module 'win32com' from 'C:\Python27\lib\site-packages\win32com\__init__.pyc'>, win32com.client = <module 'win32com.client' from 'C:\Python27\lib\site-packages\win32com\client\__init__.pyc'>, win32com.client.Dispatch = <function Dispatch> 
C:\Python27\lib\site-packages\win32com\client\__init__.py in Dispatch(dispatch='ADODB.Connection', userName=None, resultCLSID=None, typeinfo=None, UnicodeToString=None, clsctx=21) 
 93   """
 94   assert UnicodeToString is None, "this is deprecated and will go away"
 95   dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
 96   return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
 97   dispatch = 'ADODB.Connection', userName = None, global dynamic = <module 'win32com.client.dynamic' from 'C:\Python27\lib\site-packages\win32com\client\dynamic.pyc'>, dynamic._GetGoodDispatchAndUserName = <function _GetGoodDispatchAndUserName>, clsctx = 21 
C:\Python27\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName(IDispatch='ADODB.Connection', userName='ADODB.Connection', clsctx=21) 
113         else:
114                 userName = str(userName)
115         return (_GetGoodDispatch(IDispatch, clsctx), userName)
116 
117 def _GetDescInvokeType(entry, default_invoke_type):
global _GetGoodDispatch = <function _GetGoodDispatch>, IDispatch = 'ADODB.Connection', clsctx = 21, userName = 'ADODB.Connection' 
C:\Python27\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch='ADODB.Connection', clsctx=21) 
 90                         IDispatch = pythoncom.connect(IDispatch)
 91                 except pythoncom.ole_error:
 92                         IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
 93         else:
 94                 # may already be a wrapped class.

IDispatch = 'ADODB.Connection', global pythoncom = <module 'pythoncom' from 'C:\windows\system32\pythoncom27.dll'>, pythoncom.CoCreateInstance = <built-in function CoCreateInstance>, builtin None = None, clsctx = 21, pythoncom.IID_IDispatch = IID('{00020400-0000-0000-C000-000000000046}') 

<class 'pywintypes.com_error'>: (-2147024770, 'The specified module could not be found.', None, None) 
  argerror = None 
  args = (-2147024770, 'The specified module could not be found.', None, None) 
  excepinfo = None 
  hresult = -2147024770 
  message = '' 
  strerror = 'The specified module could not be found.' 

用于打开Excel工作簿:

def PreProcessLogger(reqNum, reqType, reqMail, reqIP, reqDate, reqTime, paraLogFile, PDRP, CIAG, CIAY):
    xlapp = win32com.client.Dispatch(r"Excel.Application")
    wb = xlapp.Workbooks.Open(logfilepath + '\\' + "Request Log.xlsx")

对于最后一行,它会抛出错误:

<type 'exceptions.AttributeError'>: Excel.Application.Workbooks 
      args = ('Excel.Application.Workbooks',) 
      message = 'Excel.Application.Workbooks' 

并发送以下代码的Outlook消息:

def ErrorMailer(recipient, cc, queryNum, error):
    olapp = win32com.client.Dispatch('Outlook.Application')
    msg = olapp.CreateItem(0)
    msg.to = recipient
    msg.cc = cc
    msg.subject = 'Error in the query no. ' + str(queryNum)
    mail = 'Query number ' + str(queryNum) + ' resulted in error'
    mail += '\nThe error text is ' + str(error)
    msg.body = mail
    msg.send

在最后一行抛出以下错误:

Traceback (most recent call last):
  File "E:/CasualUserInterface/CUI - Deployment Package/Test Webapp/webapp/cgi-bin/generate_list.py", line 34, in <module>
olmail()
  File "E:/CasualUserInterface/CUI - Deployment Package/Test Webapp/webapp/cgi-bin/generate_list.py", line 32, in olmail
    msg.send
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 511, in __getattr__
    ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
com_error: (-2147467260, 'Operation aborted', None, None)

再次提一下,代码在Python webserver上工作正常,但在Apache webserver上抛出这些错误

任何帮助将不胜感激。 感谢

0 个答案:

没有答案