[Zope] Zope, COM and Outlook

Igor Leturia IGOR@emun.com
Wed, 28 May 2003 12:49:31 +0200


  Hi all!

  I need to obtain someone's e-mail address from Outlook's default
address book. I found a piece of python code in the internet which I
modified, and it now looks like this:

import codecs, win32com.client

def obtainaddress(name):
    # Create instance of Outlook
    o =3D win32com.client.Dispatch("Outlook.Application")
    mapi =3D o.GetNamespace("MAPI")
    folder =3D
mapi.GetDefaultFolder(win32com.client.constants.olFolderContacts)
    print folder.Item("Igor Leturia").Address
    o =3D None

obtainaddress('Igor')

  The code needs win32com, so I installed ActivePython and copied the
win32com folder to Zope's lib. I tested the code in Zope's python and it
works.

  But as I need to access it from Zope, I included the function in one
of the Zope source modules (User.py to be precise). And when I call it
from DTML, it gives me an error:

Error Type: com_error
Error Value: (-2147221008, 'CoInitialize not called.', None, None)

  I've put some traces and I know the error is in the first line, o =3D
win32com.client.Dispatch("Outlook.Application").=20

  Any ideas? Thanks in advance,

			Igor Leturia

P.S.: Zope's traceback says:

Traceback (innermost last):
  File C:\Zope\lib\python\ZPublisher\Publish.py, line 150, in
publish_module
  File C:\Zope\lib\python\ZPublisher\Publish.py, line 114, in publish
  File C:\Zope\lib\python\Zope\__init__.py, line 159, in
zpublisher_exception_hook
    (Object: Zope)
  File C:\Zope\lib\python\ZPublisher\Publish.py, line 98, in publish
  File C:\Zope\lib\python\ZPublisher\mapply.py, line 88, in mapply
    (Object: AAAAA)
  File C:\Zope\lib\python\ZPublisher\Publish.py, line 39, in call_object
    (Object: AAAAA)
  File C:\Zope\lib\python\OFS\DTMLMethod.py, line 130, in __call__
    (Object: AAAAA)
  File C:\Zope\lib\python\DocumentTemplate\DT_String.py, line 473, in
__call__
    (Object: AAAAA)
  File C:\Zope\lib\python\DocumentTemplate\DT_Util.py, line 159, in eval
    (Object: acl_users.getUser('IGOR').getMail())
    (Info: acl_users)
  File <string>, line 2, in f
  File C:\Zope\lib\python\AccessControl\User.py, line 299, in getMail
  File C:\Archivos de
programa\Python21\Lib\site-packages\win32com\client\__init__.py, line
92, in Dispatch
  File C:\Archivos de
programa\Python21\Lib\site-packages\win32com\client\dynamic.py, line 81,
in _GetGoodDispatchAndUserName
  File C:\Archivos de
programa\Python21\Lib\site-packages\win32com\client\dynamic.py, line 72,
in _GetGoodDispatch
com_error: (see above)