[英]Accessing Outlook.Application via Python using win32com results in error
We have an application which accesses user's outlook account via the following code snippet (see the most upvoted answer): Reading e-mails from Outlook with Python through MAPI我们有一个应用程序,它通过以下代码片段访问用户的 Outlook 帐户(请参阅最受好评的答案): 通过 MAPI 使用 Python 从 Outlook 中读取电子邮件
import win32com.client
...
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
It worked fine for several months, alas, a few days ago, it began to fail on all of the organization machines, while returning the following error: AttributeError: 'module' object has no attribute 'CLSIDToClassMap'它工作了好几个月,唉,几天前,它开始在所有组织机器上失败,同时返回以下错误: AttributeError: 'module' object has no attribute 'CLSIDToClassMap'
The source of the error is: WinPython-32bit-3.4.4.2\\python-3.4.4\\lib\\site-packages\\win32com\\client\\gencache.py错误来源为:WinPython-32bit-3.4.4.2\\python-3.4.4\\lib\\site-packages\\win32com\\client\\gencache.py
I suspect it's related to a security patch applied to Outlook.我怀疑这与应用于 Outlook 的安全补丁有关。 We use Office 2010 (Outlook 14.0.7173.500 32-bit)
我们使用 Office 2010(Outlook 14.0.7173.500 32 位)
internet has trace of the same problem dating year 2007 : https://mail.python.org/pipermail/python-win32/2007-August/006147.html .互联网有 2007 年相同问题的痕迹: https : //mail.python.org/pipermail/python-win32/2007-August/006147.html 。
maybe ask the person也许问这个人
The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).此属性错误的主要原因是您的 COM 服务器已从后期绑定(动态)转换为早期绑定(静态)。
There are two ways to fix this issue:有两种方法可以解决此问题:
Use the dynamic module to force your code to work in a late-bound oriented way.使用动态模块强制您的代码以面向后期绑定的方式工作。 Example use:
使用示例:
"win32com.client.dynamic.Dispatch()" instead of "win32com.client.Dispatch()"
Use camelcase sensitive keywords for the early bound oriented way.使用驼峰敏感关键字作为早期面向绑定的方式。 Example use:
使用示例:
"excel.Visible()" instead of "excel.VISIBLE()" or "excel.visible()"
Or you can also delete the gen_py folder from temp as it makes win32com run in an early binding way.或者您也可以从 temp 中删除 gen_py 文件夹,因为它使 win32com 以早期绑定方式运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.