[英]Connect to OPCUA server with username and password
我正在使用 UAExpert 应用程序,我正在使用这些设置连接到我的机器:
我想用 python 连接到我的设备。我有这段代码,但它不起作用。
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()
我收到此错误:
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/安全策略#Basic256Sha256
更新:
我认为这是证书的问题。 所以我从 UAExpert 设置中找到了它从哪里获取证书。 我对
cert.der
使用相同的路径,但我不知道在哪里可以找到key.pem
好的,所以我成功了。 这是我当前的代码:
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())
我从这里创建的 certificate.pem 和 key.pem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.