Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

windows - Retrieving outlook Contacts via python win32com

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~1ManojLOCALS~1Tempgen_py2.70062FFF-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)

I don't understand why it's throwing the error, as I do have a profile named Outlook

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...