Trying to Connect with AsyncIo #1911
RichardDL99
started this conversation in
General
Replies: 1 comment
-
|
you are mixing up standard python ssl with opcua-asyncio library. for opcua connections you should use the library client directly, not raw ssl sockets. here is the correct way: import asyncio
from asyncua import Client
from asyncua.crypto.security_policies import SecurityPolicyBasic256Sha256
async def main():
url = "opc.tcp://127.0.0.1:48030"
client = Client(url=url)
# for encrypted connection with certificates
await client.set_security(
SecurityPolicyBasic256Sha256,
certificate="C:/Certificates/client_cert.pem",
private_key="C:/Certificates/client_key.pem",
server_certificate="C:/Certificates/server_cert.pem" # optional
)
# if server requires auth
client.set_user("username")
client.set_password("password")
try:
await client.connect()
print("Connected!")
# read some data
node = client.get_node("ns=2;i=1")
value = await node.read_value()
print(f"Value: {value}")
finally:
await client.disconnect()
if __name__ == "__main__":
asyncio.run(main())for no encryption but with username/password: client = Client(url=url)
client.set_user("username")
client.set_password("password")
await client.connect()the wrong version number error you got is because opcua uses its own binary protocol over tcp, not https/tls directly. the library handles all of that internally. make sure your server certificate is trusted. first time connection you might need to accept the client cert in server config like you did with uaexpert. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I’m trying to connect to an OPCUA server using Python and the AsyncIo library. I’ve not been using Python for long, and am completely new to async and certificates. The OPCUA server is running on my PC and I can adjust its configuration. I can connect using the OPCUA library but some data is not decoded. To make the AsyncIo connection I think I first have to load certificates, and I’m using this code:
When that runs it says: Connection failed: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1032)
After the first time it says about having to close a previous connection, so I think that code needs a closing action.
When I connect with UaE it has a username+pwd. The first time, a certificate appeared in the certificates section of the server. I “trusted” that certificate and after that UaE can connect and view data. Maybe the above code should work like that, but how do I give it username+pwd?
Any advice appreciated.
Beta Was this translation helpful? Give feedback.
All reactions