通过 python win32com 检索 Outlook 联系人
问题描述:
我正在尝试使用 Python
从 Outlook
中获取联系人.代码是:
I am Trying to get Contacts out of Outlook
using Python
.
The code is :
import win32com.client
import pywintypes
o = win32com.client.Dispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")
profile = ns.Folders.Item("Outlook")
contacts = profile.Folders.Item("Contacts")
但它给出了这样的错误:
but its giving error like this:
Traceback (most recent call last):
File "my_pro.py", line 7, in <module>
profile = ns.Folders.Item("Outlook")
File "C:\DOCUME~1\Manoj\LOCALS~1\Temp\gen_py\2.7\00062FFF-0000-0000-C000-00000
0000046x0x9x3\_Folders.py", line 70, in Item
ret = self._oleobj_.InvokeTypes(81, LCID, 1, (9, 0), ((12, 1),),Index
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, u'Microsoft Of
fice Outlook', u'The operation failed. An object could not be found.', None, 0,
-2147221233), None)
我不明白为什么它会抛出错误,因为我有一个名为 Outlook
I don't understand why it's throwing the error, as I do have a profile named Outlook
答
您可能没有名为Outlook"的配置文件(除非您创建了一个)
You probably don't have a profile named "Outlook" (Unless you created one)
通常个人资料名称"是顶级文件夹的名称,即您的收件箱"所在.如个人文件夹"
Usually the "Profile Name" is the name given to the top level folder, that your "Inbox" is in. As in "Personal Folders"