使用 win32com 通过 Python 访问 Outlook.Application 导致错误 [英] Accessing Outlook.Application via Python using win32com results in error

查看:49
本文介绍了使用 win32com 通过 Python 访问 Outlook.Application 导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,它通过以下代码片段访问用户的 Outlook 帐户(请参阅最受好评的答案):使用 Python 通过 MAPI 从 Outlook 读取电子邮件

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

import win32com.client
...
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

运行好几个月了,唉,前几天,在所有组织机器上开始出现故障,同时返回以下错误:AttributeError: 'module' 对象没有属性 'CLSIDToClassMap'

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'

错误的来源是:WinPython-32bit-3.4.4.2python-3.4.4libsite-packageswin32comclientgencache.py

The source of the error is: WinPython-32bit-3.4.4.2python-3.4.4libsite-packageswin32comclientgencache.py

我怀疑这与应用于 Outlook 的安全补丁有关.我们使用 Office 2010(Outlook 14.0.7173.500 32 位)

I suspect it's related to a security patch applied to Outlook. We use Office 2010 (Outlook 14.0.7173.500 32-bit)

推荐答案

此属性错误的主要原因是您的 COM 服务器已从后期绑定(动态)转换为早期绑定(静态).

The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).

  • 在后期绑定中,每当调用一个方法时,都会向对象查询该方法,如果成功,则可以进行调用.
  • 在Early Binding中,对象模型的信息是根据对象调用提供的类型信息预先确定的.早期绑定使用 MakePy.此外,早期绑定区分大小写.

有两种方法可以解决此问题:

There are two ways to fix this issue:

  1. 使用动态模块强制您的代码以面向后期绑定的方式工作.示例使用:

  1. 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()"
    

  • 或者你也可以从 temp 中删除 gen_py 文件夹,因为它使 win32com 以早期绑定的方式运行.

    Or you can also delete the gen_py folder from temp as it makes win32com run in an early binding way.

    这篇关于使用 win32com 通过 Python 访问 Outlook.Application 导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆