4

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

1 Answers1

3

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.

Schroeder
  • 749
  • 4
  • 10
  • If I implement this, I get the following error: ```opcua.ua.uaerrors._auto.BadCertificateUriInvalid: "The URI specified in the ApplicationDescription does not match the URI in the certificate."(BadCertificateUriInvalid)``` – JoostBerkers Oct 04 '22 at 07:49
  • The subjectAltName must match the ApplicationDescription. Default is "urn:freeopcua:client" or change it via client.application_uri = ... – Schroeder Oct 04 '22 at 08:08