FreeOpcUa / python-opcua

LGPL Pure Python OPC-UA Client and Server
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
1.32k stars 661 forks source link

Normal connection -> Communication ends after about 1 hour!! Anyone who knows the exception information below #1484

Open zeroche72 opened 1 year ago

zeroche72 commented 1 year ago

I succeeded in connecting Siemens CPU through OPC-UA communication. (Attach the code below) However, after a certain period of time, it is terminated after an exception occurs as shown below. Anyone who knows why please help me

########################### My Code from opcua import Client import logging import time from datetime import datetime

url = "opc.tcp://10.27.176.101:4840"

client = Client(url) client.set_user("OpcUaClient") client.set_password("12345678") client.connect()

while True: try: ____ rst = client.get_node("ns=2;s=/Channel/Spindle/driveLoad[1]")
____ print(rst.get_value()) ____print('#==================#') ____time.sleep(0.05) except(TimeoutError): ____print('-------------------------------------timeout') ____ print(str(TimeoutError)
____continue

############################### exception information ERROR:opcua.client.ua_client.Socket:Protocol Error Traceback (most recent call last): File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 101, in _run self._receive() File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 112, in _receive msg = self._connection.receive_from_socket(self._socket) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 363, in receive_from_socket return self.receive_from_header_and_body(header, ua.utils.Buffer(body)) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 328, in receive_from_header_and_body self._check_sym_header(security_header) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 276, in _check_sym_header self.next_security_token.TokenId)) opcua.ua.uaerrors._base.UaError: Invalid security token id 6, expected 5 or 0 ERROR:opcua.client.ua_client.Socket:Protocol Error Traceback (most recent call last): File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 101, in _run self._receive() File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 112, in _receive msg = self._connection.receive_from_socket(self._socket) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 363, in receive_from_socket return self.receive_from_header_and_body(header, ua.utils.Buffer(body)) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 335, in receive_from_header_and_body return self._receive(chunk) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 366, in _receive self._check_incoming_chunk(msg) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\connection.py", line 311, in _check_incoming_chunk .format(self._peer_sequence_number, num)) opcua.ua.uaerrors._base.UaError: Wrong sequence 3061 -> 3063 (server bug or replay attack) Traceback (most recent call last): File "test.py", line 45, in Exception in thread Thread-2: Traceback (most recent call last): File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\client.py", line 68, in run val = server_state.get_value() File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\node.py", line 153, in get_value result = self.get_data_value() File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\node.py", line 162, in get_data_value return self.get_attribute(ua.AttributeIds.Value) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\node.py", line 273, in get_attribute result = self.server.read(params) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 337, in read data = self._uasocket.send_request(request) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 83, in send_request data = future.result(self.timeout) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\concurrent\futures_base.py", line 434, in result raise TimeoutError() concurrent.futures._base.TimeoutError logWrite(str(rst.get_value()))

File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\node.py", line 153, in get_value result = self.get_data_value() File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\node.py", line 162, in get_data_value return self.get_attribute(ua.AttributeIds.Value) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\common\node.py", line 273, in get_attribute result = self.server.read(params) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 337, in read data = self._uasocket.send_request(request) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\site-packages\opcua\client\ua_client.py", line 83, in send_request data = future.result(self.timeout) File "C:\Users\jm0902.kim\AppData\Local\Programs\Python\Python36\lib\concurrent\futures_base.py", line 434, in result raise TimeoutError() concurrent.futures._base.TimeoutError

schroeder- commented 1 year ago

This library is not supported anymore (#1475). Try to migrate to asyncua and if the bug still exists we will look into it in asyncua.