thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.74k stars 844 forks source link

[BUG] OPC UA identification by user/password fails 'uacrypto' is not defined #741

Closed ysimonx closed 2 years ago

ysimonx commented 2 years ago

I am trying to connect an OPCUA Server configured with an user/password access : the connexion fails

while I am able to connect anonymously, when i configure the opcua connexion with a username and a password

 "identity": {
      "username": "operator",
      "password": "operator"
    },

the OPC UA connexion is not done beetween thingsboard-gateway and OPC UA Server (loytec device)

when I Try this connexion with another OPC UA client (prosys) : the connexion is ok

so this is really a thingsboard-gateway issue

OPC-UA Connector:

Error traceback:


""2022-02-09 16:58:56" - |ERROR| - [opcua_connector.py] - opcua_connector - __connect - 130 - name 'uacrypto' is not defined"
""2022-02-09 16:59:07" - |ERROR| - [opcua_connector.py] - opcua_connector - __connect - 130 - name 'uacrypto' is not defined"
""2022-02-09 16:59:17" - |ERROR| - [opcua_connector.py] - opcua_connector - __connect - 130 - name 'uacrypto' is not defined"
""2022-02-09 16:59:27" - |ERROR| - [opcua_connector.py] - opcua_connector - __connect - 130 - name 'uacrypto' is not defined"
""2022-02-09 16:59:38" - |ERROR| - [opcua_connector.py] - opcua_connector - __connect - 130 - name 'uacrypto' is not defined"

Versions from master branch of thingsboard-gateway :

imbeacon commented 2 years ago

Hi @ysimonx ,

Please try to install the package cryptography. You can do this with the following command:

pip3 install cryptography

ysimonx commented 2 years ago

Yes, I just found this solution

I will propose a fix like this :

try:   
    from opcua.crypto import uacrypto
except ImportError:
    TBUtility.install_package("cryptography")
    from opcua.crypto import uacrypto

With this code, i manage to connect !

Thank you @zbeacon

imbeacon commented 2 years ago

Yes, It is probably the best solution for issues like this. Cryptography should installs during setup and it is strange that it wasn't install.

ysimonx commented 2 years ago

@zbeacon : PR https://github.com/thingsboard/thingsboard-gateway/pull/742 ;-)

thank you

imbeacon commented 2 years ago

@ysimonx Thank you for your participating in the project life. We appreciate it.