ya-mouse / openopc

OpenOPC for Python3.4
Other
48 stars 56 forks source link

OpenOPC.client() fails with "OPCError: Dispatch: Invalid class string" #14

Open bwllc opened 4 years ago

bwllc commented 4 years ago

Please correct my misunderstanding if I am wrong. The README.TXT leads me to believe that this version of OpenOPC is an updated version of the package that was originally described at http://openopc.sourceforge.net/. As such, I think that I should expect the "minimal working program" code to work. Here is an interpreter session with traceback showing that I am failing right from the start:

Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import OpenOPC
>>> OpenOPC.__version__
'1.2.0'
>>> opc = OpenOPC.client()
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py",
line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenOPC.py", line 167, in __init__
    self._opc = win32com.client.gencache.EnsureDispatch(c, 0)
  File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py",
 line 527, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\__init__.py",
 line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py",
line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py",
line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenOPC.py", line 173, in __init__
    raise OPCError(error_msg)
OpenOPC.OPCError: Dispatch: Invalid class string

I'm failing just by attempting to create a client with no arguments. I installed this package from PyPI using pip. Both win32 and pyro4 were installed when I installed OpenOPC.

Advice and suggestions are greatly appreciated, thanks!

bwllc commented 4 years ago

Followup message: I modified a copy of OpenOPC.py to attempt to track down the error. Here's some more output:

>>>cli = client()
In client.__init__.
opc_class_list = ['Matrikon.OPC.Automation', 'Graybox.OPC.DAWrapper', 'HSCOPC.Automation', 'RSI.OPCAutomation', 'OPC.Automation']
In EnsureDispatch loop.
0 Matrikon.OPC.Automation
1 Graybox.OPC.DAWrapper
2 HSCOPC.Automation
3 RSI.OPCAutomation
4 OPC.Automation
Traceback (most recent call last):

  File "<ipython-input-10-ae3667f094cc>", line 1, in <module>
    cli = client()

  File "C:/Users/...openopc-master/src/OpenOPC_debug.py", line 177, in __init__
    raise OPCError(error_msg)

OPCError: Dispatch: Invalid class string
>>>

So I don't know what OPC class strings are yet, but most of them are valid. The last one, 'OPC.Automation', is not valid. If I remove this item from opc_class_list before entering the EnsureDispatch loop, I can create a client.

I have a workaround, but I don't know why I need a workaround or what I may have just broken. Advice appreciated, thanks!

twodonkeys commented 4 years ago

hi,man,i had the same problem ,how to fixed it?

Traceback (most recent call last): File "D:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch IDispatch = pythoncom.connect(IDispatch) pywintypes.com_error: (-2147221005, '无效的类字符串', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\ProgramData\Anaconda3\lib\site-packages\OpenOPC.py", line 167, in init self._opc = win32com.client.gencache.EnsureDispatch(c, 0) File "D:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch disp = win32com.client.Dispatch(prog_id) File "D:\ProgramData\Anaconda3\lib\site-packages\win32com\client__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "D:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221005, '无效的类字符串', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\ProgramData\Anaconda3\lib\site-packages\OpenOPC.py", line 173, in init raise OPCError(error_msg) OpenOPC.OPCError: Dispatch: 无效的类字符串

jamesbraza commented 1 year ago

This could be caused by missing DLL(s) per https://sourceforge.net/p/openopc/discussion/709251/thread/219327d9/