python-opcua
python-opcua copied to clipboard
Node id from string containing ';' character throws exception
For a node id string like this: 'ns=2;s=myId;something'
which is a valid node id string, but contains a ; in the identifier, the python opc-ua library throws the following exception, when I try to create a NodeId from the string:
Traceback (most recent call last):
File "C:\Users\smg.SRO\AppData\Local\Programs\Python\Python36-32\lib\site-packages\opcua\ua\uatypes.py", line 339,
in from_string return NodeId._from_string(string)`
File "C:\Users\smg.SRO\AppData\Local\Programs\Python\Python36-32\lib\site-packages\opcua\ua\uatypes.py", line 354,
in _from_string k, v = el.split("=", 1) ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\smg.SRO\AppData\Local\Programs\Python\Python36-32\lib\site-packages\opcua\client\client.py", line 509,
in get_node return Node(self.uaclient, nodeid)
File "C:\Users\smg.SRO\AppData\Local\Programs\Python\Python36-32\lib\site-packages\opcua\common\node.py", line 46,
in __init__ self.nodeid = ua.NodeId.from_string(nodeid)
File "C:\Users\smg.SRO\AppData\Local\Programs\Python\Python36-32\lib\site-packages\opcua\ua\uatypes.py", line 341,
in from_string raise UaStringParsingError("Error parsing string {0}".format(string), ex) opcua.ua.uaerrors._base.UaStringParsingError:
("Error parsing string ns=2;s=myId;something", ValueError('not enough values to unpack (expected 2, got 1)',))
As far as I have seen the problem is in the _from_string function in the NodeId class (uatypes.py file at line 344). The split on the semicolon from line 345 in my opinion should be done until the first occurrence of the ; and not all ; characters (like in case of the = at line 354).
I'm not an expert in the OPC UA standard, so I might be mistaken. Please let me know if this is correct as it is or not in your opinion.
Regards, Gabor.
Hi szmgabor,
I am facing the same problem. Have you found out any solution for your problem?
Kind regards Thomas
it might be that we fixed that in opcua-asyncio
Hi @TommyTomson585,
This was quite some time ago, but as far as I remember I've written my own implementation of the _from_string
function.
The fix to this problem was rather simple, instead of l = string.split(";")
you need l = string.split(";", 1)
on the first line of that function.
Regards, Gabor
why no PR ?
Hi @all,
@szmgabor :It works fine with changing the "string.split" function.
@AndreasHeine: I tried it according to the 'client_to_kepware' example. But unfortunately it doesn't work with a string including two times ';'
But after all thank you for the feedback.
Regards
Thomas
this is fixed in opcua-asyncio
@TommyTomson585, I'm glad it worked.