[python-win32] Problem after running MakePy

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Dec 9 10:56:48 CET 2005


[Rudy Schockaert]

> I have a python program that does some things on 
> Exchange mailboxes. I use the MAPI.Session object 
> for this and create it like this:

> import win32com.client 
> MAPISession = win32com.client.Dispatch("MAPI.Session")
> MAPISession.Logon()
> for infostores in MAPISession.InfoStores:
>   print infostores.Name

> If I now use makepy to create a genpy for the CDO 1.21 
> library (MAPI.Session) I get the following result:

[... snip ...]

> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File
"C:\Python24\lib\site-packages\win32com\gen_py\3FA7DEA7-6438-101B-ACC1-0
0AA00423326x0x1x21.py ", line 3039, in > __getitem__
>     return self._get_good_object_(self._oleobj_.Invoke(*(21, LCID, 2,
1, item)), "Item")
> com_error: (-2147352565, 'Invalid index.', None, None)

OK, this is the quick get-you-working answer. For the longer answer, 
I'd have to look at the makepy-generated module and at the code
for the DispatchBaseClass. It's almost certainly down to the fact
that COM objects generally use 1-based indexing, while Python
ones use 0-based.

Do it this way:

<code>
import win32com.client.gencache import EnsureDispatch

MAPISession = EnsureDispatch ("MAPI.Session")
MAPISession.Logon ()
for n in range (len (MAPISession.InfoStores)):
  # n will be 0, 1, 2, 3... while
  #  InfoStores items are 1, 2, 3...
  #  so add 1 to make up the difference
  store = MAPISession.InfoStores[1 + n]
  print store.Name

</code>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list