Open ns247 opened 6 years ago
Are you unit testing this on purpose?
Yes, it was on purpose.
The posted code still fails with the same error even when it isn't wrapped as part of a unit test.
Ok, we get a lot of people new to python so I had to ask. User management stuff is not really implemented. pull requests welcome.
No problem!
To be clear I'm trying to use the python FreeOpcUa client to connect to a third party server, not set up a FreeOpcUa server.
It looks like this should already be covered by the tests already:
Not sure why it's failing for me.
Are you using Python 2 or 3?
I would step through the code and see where your string is turning into bytes, because https://github.com/FreeOpcUa/python-opcua/blob/master/opcua/ua/ua_binary.py#L69 needs a string.
I remember this was added by a PR and might be missing a test... Looks like somewhere bytes are written when code expect a string.. What version of Python?
I'm also curious if using the admin@127.0.0.1
style is handled differently than set_user
.
I'm using Python 3.4 on Windows, I get the same error if I use this style instead:
client = Client("opc.tcp://opctest:test@127.0.0.1:53530/OPCUA/SimulationServer")
I'll step through my code and try to find out where it's becoming bytes.
Some progress in the following section of code:
Inspecting I find this:
uatype = {str} 'String'
val = {bytes} b'username_basic256'
vtype = {VariantType} VariantType.String
So the value is bytes, but it thinks the type is String.
Earlier in the trace I can see:
Password = {bytes} b'test'
PolicyId = {bytes} b'username_basic256'
UserName = {str} 'opctest'
ua_types = {list} <class 'list'>: [('PolicyId', 'String'), ('UserName', 'String'), ('Password', 'ByteString'), ('EncryptionAlgorithm', 'String')]
So looks like the problem is only with PolicyId, not the UserName or Password.
So the schema xml files define PolicyId to be a string:
But the code defines it as bytes:
I'm not familiar enough with this project to know which way round this bug is.
I guess the next question is why is the built in test I linked before passing.
Okay, so it appears our OPC UA Server wasn't returning appropriate policy id's, so it was falling through to the default of b"username_basic256".
When tested against a server that correctly returns the right username policy everything works as expected.
I've created a pull request: #643
When trying to connect to an OPC server with a username and password using the following code an AttributeError is thrown:
Traceback:
Anonymous authentication works fine.