Search code examples
pythoncom64-bitwin32com32-bit

Python win32com - Class not registered error


I'm trying to control a device (Gamry Interface 5000 Potentiostat) via its COM interface using win32com.

# Imports
import win32com.client as client

# Get device list
devices = client.Dispatch('GamryCOM.GamryDeviceList')

# Iterate through devices
for i in range(devices.Count()):
    # Get device (this wors as we only have one connected yet)
    device = devices.EnumSections()[i]
    print(device)
    
# Setup potentiostat object
potentiostat = client.Dispatch('GamryCOM.GamryPstat')

When I run this, I got the following error message:

IFC5000-10519
Traceback (most recent call last):
  File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\[...]\gamry_control_01.py", line 23, in <module>
    potentiostat = client.Dispatch('GamryCOM.GamryPstat', clsctx = pythoncom.CLSCTX_LOCAL_SERVER )
  File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\__init__.py", line 117, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
  File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\dynamic.py", line 88, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)

Funnily enough, the first dispatch-statement just works fine, Just the second one fails.

I'm using a 64 Bit Windows 11 setup and tested different Python environments:

  • Python 3.10 64 Bit, win32com-303 64 Bit
  • Python 3.9 32 Bit, win32com-303 32 Bit

I also tried using comtypes instead of win32com which resulted in the same error.

Thank you very much for your help!

Regards


Solution

  • I had the same problem and contacted a Salesman. He sent me a document, saying that on some devices you have to use pstat = client.CreateObject('GamryCOM.GamryPC5Pstat') for the Reference family and pstat = client.CreateObject('GamryCOM.GamryPC6Pstat') for the Interface family. For me, at least the OSError: [WinError -2147221164] Class not registered disappears. I've used "comtypes".