[python-win32] Connecting to Bloomberg

michel.gba at derivativepartners.com michel.gba at derivativepartners.com
Mon Apr 23 10:40:02 CEST 2012

Hi Tim and all,
Thanks for your reply... I thought would be helpful looking at the error code from win32, I got.
Basically, I'm getting error in the _init_.py line 85, 95, 108 and 245. See below.
I got this error in all programs I try to implement  win32com.client module.
I'm quite new Python user and I will appreciate your kind further help.

Best Regards,

/************************************ Errror code ******************************************/
Traceback (most recent call last):
  File "C:\Python32\Pythondev\minimal.py", line 12, in <module>
    session = win32com.client.DispatchWithEvents('blpapicom.Session.1' , EventHandler)
  File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 245, in DispatchWithEvents
    disp = Dispatch(clsid)
  File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)


import win32com.client
from pythoncom import PumpWaitingMessages
from time import time

class EventHandler:
    def OnProcessEvent(self, result)
        event = win32com.client.gencache.EnsureDispatch(result) 
        iterator = event.CreateMessageIterator()
        while iterator.Next():
            print "EventType[%d] -> %s" % (event.EventType, iterator.Message.MessageTypeAsString,)
session = win32com.client.DispatchWithEvents('blpapicom.Session.1' , EventHandler)

## Each one of these gives rise to another message
started = session.OpenService('//blp/mktdata')

endTime = time() + 2
while True:
    if endTime < time():                

Best Regards,

Michel Gba
Derivative Partners Research AG
Splügenstrasse 10
8002 Zürich, Schweiz

tel: +41 (0) 44 515 27 79
fax: +41 (0) 43 305 05 31
mail: michel.gba at derivativepartners.com
home: www.derivativepartners.com

+++ all about structured products on www.payoff.ch +++

-----Original Message-----
From: python-win32-bounces+michel.gba=derivativepartners.com at python.org [mailto:python-win32-bounces+michel.gba=derivativepartners.com at python.org] On Behalf Of Tim Roberts
Sent: Freitag, 20. April 2012 18:55
To: Python-Win32 List
Subject: Re: [python-win32] Connecting to Bloomberg

michel.gba at derivativepartners.com wrote:
> I want to connect to Bloomberg with Python 3.2.
> Looking on internet I found couple of programs written by diverse 
> authors. I implemented by It does not work.
> I followed the following steps, I included the python code and the 
> error messages:
> I will really appreciate if you could help me.
> ...
> Step 1 : Install Bloomberg Desktop API v3 from API <GO> download page 
> (file is contained in DAPI_2.zip)
> Step 2 : Download and install : ActiveState Python x86 (Key point :
> not the 64-bit version)
> Step 3 : (For safety) :

Are you on a 64-bit operating system?  Are you entirely sure that the Bloomberg Desktop API v3 a 32-bit service?  Remember that you can ONLY call a 32-bit in-process server from a 32-bit application, and a 64-bit server from a 64-bit application.

You could check in the registry.  If you find an entry under
then you have a 64-bit version.  If you find an entry under
then you have a 32-bit version.

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

python-win32 mailing list
python-win32 at python.org

More information about the python-win32 mailing list