我正在使用 UAEexpert 应用程序,并使用以下设置连接到我的计算机:
我想用 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("没有匹配的端点:{0},{1}".format(security_mode,policy_uri)) opcua.ua.uaerrors._base.UaError:没有匹配的端点:2,http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256
更新:
我认为是证书的问题。所以我从 UAEExpert 设置中找到了它从哪里获取证书。 我对
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 这里
我尝试仅使用用户名和密码连接到 OPC UA。 使用 Python
asyncua
版本的库 1.0.4
下面是我的代码片段:
async with Client(url=self._url, timeout=2) as client:
# client.activate_session(username="guest", password="guest")
await client.set_user("guest")
await client.set_password("guest")
我检查了不同的选项,但仍然出现错误:
The user identity token is not valid.(BadIdentityTokenInvalid)
UaExpert 正在使用用户名和密码进行连接,没有任何问题。
有人可以告诉我我做错了什么吗?
谢谢你