Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect with OPCUA server with Basic256Sha256 in Python

Tags:

python

opc-ua

Te following code is used to connect with the opcua server:

from opcua import Client
client = Client(url='opc.tcp://192.168.0.5:4840')


client.set_user('user1')
client.set_password('password')
client.connect()

Error message:

Received an error: MessageAbort(error:StatusCode(BadSecurityPolicyRejected), reason:None) Protocol Error

I also tried to append this code:

client.set_security_string("Basic256Sha256,Sign,cert.pem,key.pem")

But I do not know where I can create de cert.pem and key.pem

Does anyone know how to connect with the server in python

like image 900
JoostBerkers Avatar asked Oct 21 '25 20:10

JoostBerkers


1 Answers

You can use this script and adapt it to your needs: https://github.com/FreeOpcUa/python-opcua/blob/master/examples/generate_certificate.sh

Also python-opcua is deprecated. So if you start a new project, I would recommend you to use asyncua. Asyncua also has a sync wrapper if you don't want to deal with asyncio.

like image 173
Schroeder Avatar answered Oct 24 '25 10:10

Schroeder