Home > Blockchain >  How i resolve comunication problem opcua library with pyinstaller?
How i resolve comunication problem opcua library with pyinstaller?

Time:09-05

i have problem with pyinstaller i use library opcua for comunication, with normal run in pycharm everything works correctly, after create .exe with pyinstaller after few second or minute the comunication stops.

from opcua import Client
from opcua.crypto import security_policies
from opcua.ua import MessageSecurityMode
from opcua import ua

def connect(self):
        try:
            self.client.set_security(policy=security_policies.SecurityPolicyBasic256Sha256,
                                     certificate_path=self.root_path CERT_RELATIVE_PATH,
                                     private_key_path=self.root_path PRIVATE_KEY_RELATIVE_PATH,
                                     mode=MessageSecurityMode.SignAndEncrypt
                                     )
            self.client.application_uri = "urn:script:opcua"

            # self.client.secure_channel_timeout = 10000
            self.client.session_timeout = 60000

            self.client.connect()
            self.root_node = self.client.get_root_node()
            self.call_method('ns=2;s=/Methods/GiveUserAccess', 'OpcUaClient', 'GudWrite')
            return True
        except Exception:
            self.main_log.info('unable to connect to nc: {}'.format(traceback.format_exc()))
            raise custom_exceptions.UnableToConnect()

    def get_battery_100(self):
        return self.client.get_node('ns=2;s=/NC/_N_NC_GD2_ACX/DG_BATTERY_TIME').get_value()

This is the error after some data exchange:

WARNING:opcua.uaprotocol:Received an error: MessageAbort(error:StatusCode(BadSecurityChecksFailed), reason:None)
CRITICAL:opcua.client.ua_client.Socket:Received an error: MessageAbort(error:StatusCode(BadSecurityChecksFailed), reason:None)
ERROR:opcua.client.ua_client.Socket:Protocol Error
..
  File "opcua\client\ua_client.py", line 101, in _run
  File "opcua\client\ua_client.py", line 121, in _receive
  File "opcua\client\ua_client.py", line 129, in _call_callback
opcua.ua.uaerrors._base.UaError: No future object found for request: 0, callbacks in list are dict_keys([8612, 8613])
..
..
..
  File "opcua\common\node.py", line 155, in get_value
  File "opcua\common\node.py", line 164, in get_data_value
  File "opcua\common\node.py", line 275, in get_attribute
  File "opcua\client\ua_client.py", line 347, in read
  File "opcua\client\ua_client.py", line 83, in send_request
  File "concurrent\futures_base.py", line 443, in result
concurrent.futures._base.CancelledError

do you know if there is any modification to make to make it work in pyinstaller for comunication0?

(class with this module is call with a thread)

CodePudding user response:

BadSecurityChecksFailed related to security, are you shure you are destribute the correct certificates? Or if you are using your client on another device, are you matching the correct hostname/ipaddress in the certificates?

CodePudding user response:

I solved. when i created the .exe file with pyinstaller i copied the .der and .pem certificates (all in the same pc) but if i delete them and with python I recreate them automatically, the program works correctly, instead with old certificates, the connection is unstable.

  • Related