[英]Error com_error: (-2147221005, 'Invalid class string', None, None) while writing dataframe into excel binary notebook
[英]com_error: (-2147221005, 'Invalid class string', None, None)
我正在尝试使用 Python 连接到 Outlook 但以下行会引发com_error
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
完整的 Traceback 如下:
---------------------------------------------------------------------------
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)
任何建议都会有所帮助。
看起来在系统上找不到 Outlook。 请注意,在运行代码之前,您需要安装 Outlook。
也不清楚您在何时何地尝试自动化 Outlook。 Office 文章服务器端自动化的注意事项陈述如下:
Microsoft 目前不推荐也不支持任何无人参与、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)的 Microsoft Office 应用程序自动化,因为 Office 可能表现出不稳定的行为和/或死锁当 Office 在此环境中运行时。
如果您正在构建在服务器端上下文中运行的解决方案,您应该尝试使用已确保无人值守执行安全的组件。 或者,您应该尝试找到允许至少部分代码在客户端运行的替代方案。 如果您使用来自服务器端解决方案的 Office 应用程序,该应用程序将缺少许多成功运行所需的功能。 此外,您将承担整体解决方案稳定性的风险。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.