我有以下python代码
o = win32com.client.Dispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")
profile = ns.Folders.Item("Profile Name")
tasks = profile.Folders.Item("Tasks")
print tasks.Items
当我运行它时,脚本因以下错误而崩溃:
Traceback (most recent call last):
File "start.py", line 47, in <module>
o = win32com.client.Dispatch("Outlook.Application")
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)
我也试过:
win32com.client.gencache.EnsureDispatch("Outlook.Application")
不知道该怎么做以及问题出在哪里
更新:仅当 Outlook 正在运行时才会发生这种情况,但发出 getActiveObject 崩溃并显示“操作不可用”