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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With