ya-mouse / openopc

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

ProtocolError: invalid data or unsupported protocol version #9

Open vantaka2 opened 5 years ago

vantaka2 commented 5 years ago

I'm trying to connect to the Matrikon OPC Simulation server which is running on the same system.

my code:

import OpenOPC
OpenOPC.open_client('localhost')

The error: ProtocolError: invalid data or unsupported protocol version

My packages:

OpenOPC-Python3x==1.2.2 ## (via pip install of https://pypi.org/project/OpenOPC-Python3x/)
Pyro4==4.74
serpent==1.27

and using python 3.7.0:

I believe this is a problem on the python side because I am able to connect and run commands using the command line client (opc.exe): running: opc -H localhost -h localhost -s Matrikon.OPC.Simulation -r Random.Int4 successfully yields Random.Int4 32757 Good 12/10/18 19:24:24

Full error: any idea why pyro4 is causing issues here?

ProtocolError                             Traceback (most recent call last)
<ipython-input-54-34e9043002f9> in <module>
----> 1 OpenOPC.open_client('localhost')

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\OpenOPC.py in open_client(host, port)
    129    import Pyro4.core
    130    server_obj = Pyro4.Proxy("PYRO:opc@{0}:{1}".format(host, port))
--> 131    return server_obj.create_client()
    132 
    133 class TimeoutError(Exception):

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\Pyro4\core.py in __getattr__(self, name)
    273             # get metadata if it's not there yet
    274             if not self._pyroMethods and not self._pyroAttrs:
--> 275                 self._pyroGetMetadata()
    276         if name in self._pyroAttrs:
    277             return self._pyroInvoke("__getattr__", (name,), None)

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\Pyro4\core.py in _pyroGetMetadata(self, objectId, known_metadata)
    613         if self._pyroConnection is None and not known_metadata:
    614             try:
--> 615                 self.__pyroCreateConnection()
    616             except errors.PyroError:
    617                 log.error("problem getting metadata: cannot connect")

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\Pyro4\core.py in __pyroCreateConnection(self, replaceUri, connected_socket)
    594                 self._pyroConnection = socketutil.SocketConnection(connected_socket, uri.object, True)
    595             else:
--> 596                 connect_and_handshake(conn)
    597             if config.METADATA:
    598                 # obtain metadata if this feature is enabled, and the metadata is not known yet

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\Pyro4\core.py in connect_and_handshake(conn)
    533                     _log_wiredata(log, "proxy connect sending", msg)
    534                 conn.send(msg.to_bytes())
--> 535                 msg = message.Message.recv(conn, [message.MSG_CONNECTOK, message.MSG_CONNECTFAIL], hmac_key=self._pyroHmacKey)
    536                 if config.LOGWIRE:
    537                     _log_wiredata(log, "proxy connect response received", msg)

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\Pyro4\message.py in recv(cls, connection, requiredMsgTypes, hmac_key)
    166         Validates a HMAC chunk if present.
    167         """
--> 168         msg = cls.from_header(connection.recv(cls.header_size))
    169         msg.hmac_key = hmac_key
    170         if 0 < config.MAX_MESSAGE_SIZE < (msg.data_size + msg.annotations_size):

c:\users\keerthan\appdata\local\programs\python\python37\lib\site-packages\Pyro4\message.py in from_header(cls, headerData)
    150         tag, ver, msg_type, flags, seq, data_size, serializer_id, anns_size, _, checksum = struct.unpack(cls.header_format, headerData)
    151         if tag != b"PYRO" or ver != constants.PROTOCOL_VERSION:
--> 152             raise errors.ProtocolError("invalid data or unsupported protocol version")
    153         if checksum != (msg_type + ver + data_size + anns_size + flags + serializer_id + seq + cls.checksum_magic) & 0xffff:
    154             raise errors.ProtocolError("header checksum mismatch")

ProtocolError: invalid data or unsupported protocol version`
vantaka2 commented 5 years ago

@mkwiatkowski - Any thoughts? I installed OpenOPC from your fork.

Appreciate the help!

vantaka2 commented 5 years ago

Sort of solved my own issue via: https://stackoverflow.com/questions/52747503/openopc-with-python-3-6/53716394#53716394

I was using openOPCService from python 2.7.

Running everything with python 2.7 works but I can't seem to run the 3.x version of openOPCService

cesclondon87 commented 5 years ago

@vantaka2

I was using openOPCService from python 2.7.

I have your same issue with python 3.x. I'm confused. How did you started openOPCService?

vantaka2 commented 5 years ago

@cesclondon87 I am unable to start openOPCService on my own, but I was able to start it by installing openOPC from https://sourceforge.net/projects/openopc/files/.

openOPCService is started during installation.

cesclondon87 commented 5 years ago

@vantaka2
Sorry but I don't understand. My steps are: 1) Download v1.31 .exe and install it schermata 2018-12-11 alle 16 25 20

2) Test to see if the OpenOPC Gateway Service is functioning by entering: opc -m open -i => it works and i'm able to read variable schermata 2018-12-11 alle 16 26 16 schermata 2018-12-11 alle 16 26 47

3) install python 3.7 4) install via pip: OpenOPC-Python3x==1.2.2 & Pyro4==4.74 5) test with python code but it return your same initial error: import OpenOPC OpenOPC.open_client('localhost')

schermata 2018-12-11 alle 16 27 42

Thanks for your help

vantaka2 commented 5 years ago

@cesclondon87 :

I was unable to get this running with python 3.X;

What I did was steps 1 & 2 just as you did.

For step 3, I installed python 2.7 and created a virtual environment

pip install the python 2 version of OpenOPC (https://github.com/sightmachine/OpenOPC); (you could also just copy the files over from the install you did in step 1).

pip install pywin32==224 pip install pyro==3.16

Hope that helps.

cesclondon87 commented 5 years ago

@vantaka2 Now it works with your help! Thanks a lot!!

vantaka2 commented 5 years ago

@cesclondon87 - If you get it to work with python3, please let me know!

cesclondon87 commented 5 years ago

@vantaka2 certainly, of course. I need that it works with python3, too. But for the moment i think i will create a docker container with python 2.7 + flask in order to create a mini API accessible from python 3.

mattwC137 commented 5 years ago

Has anyone made any progress on this? I have successfully gotten OpenOPC to work with Python 2.7 and I downloaded and import the OpenOPC library for Python 3.4+ from this repository (https://github.com/joseamaita/openopc120). I am getting an unsupported protocol version error from Pyro4. I've checked that the local and the remote machine with the OPC server are protocol version 48. Also, the opc command line is complaining that it cannot connect to the gateway service at 0.0.0.0:7766. I have the OPC_GATE_HOST set to the hostname of my remote machine.

I am using: Python 3.6.8 32-bit Pyro4==4.55 pywin32==224

leon-h-a commented 4 years ago

Hello, I'm running in circles for a while now, have you guys solved it? @vantaka2 @cesclondon87 Thanks.

Sandeep-Chavarkar commented 3 years ago

For me this issue was resolved when I manually downloaded, extracted and installed Pyro4.8 ... I shifted to newly extracted Pyro folder and used 'python setup.py install' ... instead of using 'pip install Pyro4'

pensur commented 1 year ago

Hello @Sandeep-Chavarkar, what python version are you using? is it 32 or 64 bit? what operating system? thank you

PifMuse commented 4 months ago

I found the reason, you can't install OpenOpc directly from the installation package otherwise it using pyro to talk to the gateway service not pyro4。 i solved the issue by refer this https://joseamaita.com/en/openopc-and-python-37-on-windows/

PifMuse commented 4 months ago

BTW, using Anaconda install python doesn't work for me, I don't know why.