我试图用Python连接到Outlook,但下面一行抛出了com_error
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
完整的回溯如下:
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
c:\users\dipf5\appdata\local\programs\python\python37\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
88 try:
---> 89 IDispatch = pythoncom.connect(IDispatch)
90 except pythoncom.ole_error:
com_error: (-2147221005, 'Invalid class string', None, None)
During handling of the above exception, another exception occurred:
com_error Traceback (most recent call last)
<ipython-input-15-a96a5314c4a3> in <module>
----> 1 outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
c:\users\dipf5\appdata\local\programs\python\python37\lib\site-packages\win32com\client\__init__.py in Dispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx)
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
c:\users\dipf5\appdata\local\programs\python\python37\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName(IDispatch, userName, clsctx)
112 else:
113 userName = str(userName)
--> 114 return (_GetGoodDispatch(IDispatch, clsctx), userName)
115
116 def _GetDescInvokeType(entry, invoke_type):
c:\users\dipf5\appdata\local\programs\python\python37\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
89 IDispatch = pythoncom.connect(IDispatch)
90 except pythoncom.ole_error:
---> 91 IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
92 else:
93 # may already be a wrapped class.
com_error: (-2147221005, 'Invalid class string', None, None)
任何建议都会有帮助。
发布于 2020-06-17 15:11:32
看起来系统上找不到Outlook。注意,在运行代码之前,需要安装Outlook。
还不清楚您在何时何地尝试自动化Outlook。办公服务器端自动化的几点思考的文章陈述如下:
Microsoft目前不建议也不支持来自任何无人值守、非交互式客户端应用程序或组件(包括ASP、ASP.NET、DCOM和NT服务)的Microsoft应用程序的自动化,因为在此环境中运行Office时,Office可能会出现不稳定的行为和/或死锁。 如果您正在构建在服务器端上下文中运行的解决方案,则应尝试使用已为无人值守执行而安全的组件。或者,您应该尝试找到允许至少部分代码运行客户端的替代方案。如果您使用来自服务器端解决方案的Office应用程序,则该应用程序将缺乏许多成功运行所需的功能。此外,您将承担风险与您的整体解决方案的稳定性。
https://stackoverflow.com/questions/62427468
复制相似问题