Connect to OPCUA server with username and password

Alex

I am using UAExpert application and i am connecting to my machine with these settings: enter image description here

I want to connect to my device with python. I have this code but it doesn't work.

from opcua import Client

client = Client("opc.tcp://<ip>:4840")
client.set_user("username")
client.set_password("password")
client.set_security_string("Basic256Sha256,Sign,cert.der,key.pem")
client.connect()

I am getting this error:

raise ua.UaError("No matching endpoints: {0}, {1}".format(security_mode, policy_uri)) opcua.ua.uaerrors._base.UaError: No matching endpoints: 2, http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256

UPDATE:

I think it's the issue of the certificate. So i found from UAExpert settings where it gets the certificate from. enter image description here I use the same path for cert.der but i don't know where i can find the key.pem

Alex

Ok so i made it work. This is my current code:

import asyncio
import opcua


async def main():
    client = opcua.Client("opc.tcp://<ip>:4840", timeout=60)
    client.application_uri = "urn:<ip>:UPS1600"  # Should match in your certificate
    client.set_user("username")
    client.set_password("password")
    client.set_security_string("Basic256Sha256,SignAndEncrypt,<path_to_certificate.pem>,<path_to_key.pem")
    client.connect()
    struct = client.get_node("ns=3;i=100191")
    value= struct.get_value()
    print(value)


if __name__ == '__main__':
    asyncio.run(main())

Where certificate.pem and key.pem i have created them from here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to connect to MongoDB 3.2 in Java with username and password?

What password and username do I use for mysql_connect()?

How to connect to an ActiveMQ server by setting the username and password programmatically?

Simple username & password protection of a bokeh server

Delphi/Rdp check username and password before connect

Use socket to send username and password to tcp server

Connect to TFS GIT domain\username + password

How to use username and password (no SSL) in Java client to connect to Elasticsearch?

How to configure MongoDB to be able to connect using username and password?

How to connect with an API that requires username and password

Use windows explorer to connect to a server with username and password

Server asks for Username and Password when Uploading File

Java - Connect to MySQL without specifying username and password inside the code

How to change username in Connect to server?

FTP connect with no username and password?

connect to openvpn using username and password

orientdb connect invalid password and username

LFTP: save username/password for specific server?

How to connect mongodb(mongoose) with username and password?

How to automatically enter username and password when prompted to connect to a remote server

Using JSoup to connect to a website with username/password

How to connect LDAP With username and password?

What are the options for connect username/password@sid in a sql script for jdbc

passing username and password to the server in a secure way

Python connect to API using username, password and API key

Excel VBA Userform login with username and password on server

How to connect with coreNLP server with username password?

python paho mqtt can not connect to mqtts with username and password

Setting username and role in opcua