Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server.import_xml leading to BadParentNodeIdInvalid #715

Open
NNTin opened this issue Oct 9, 2018 · 14 comments
Open

server.import_xml leading to BadParentNodeIdInvalid #715

NNTin opened this issue Oct 9, 2018 · 14 comments

Comments

@NNTin
Copy link

NNTin commented Oct 9, 2018

I took the server-minmal.py example and added the following line between line 12 and 13:

server.import_xml("absolute-path-of-my-xml-file.xml")

It works when importing Opc.Ua.Di.NodeSet2.xml.
But when I import Opc.Ua.Fdi5.NodeSet2.xml I am getting the following error:

failure adding node NodeData(nodeid:NumericNodeId(ns=1;i=2))
Traceback (most recent call last):
  File "Z:/Tin/python/experiment/server.py", line 13, in <module>
    server.import_xml("Z:/Tin/python/xml/Opc.Ua.Fdi5.NodeSet2.xml")
  File "Z:\python-opcua\opcua\server\server.py", line 523, in import_xml
    return importer.import_xml(path, xmlstring)
  File "Z:\python-opcua\opcua\common\xmlimporter.py", line 67, in import_xml
    node = self._add_node_data(nodedata)
  File "Z:\python-opcua\opcua\common\xmlimporter.py", line 88, in _add_node_data
    node = self.add_variable_type(nodedata)
  File "Z:\python-opcua\opcua\common\xmlimporter.py", line 340, in add_variable_type
    res[0].StatusCode.check()
  File "Z:\python-opcua\opcua\ua\uatypes.py", line 233, in check
    raise UaStatusCodeError(self.value)
opcua.ua.uaerrors._auto.BadParentNodeIdInvalid: The parent node id does not to refer to a valid node.(BadParentNodeIdInvalid)

When I remove the troubling node from the xml the error changes to:
failure adding node NodeData(nodeid:NumericNodeId(ns=1;i=2))

When removing that again it changes to:
failure adding node NodeData(nodeid:NumericNodeId(ns=1;i=92))

and so on.

When I import Opc.Ua.NodeSet2.xml I am getting the following error:

AddNodesItem: Requested NodeId NumericNodeId(i=3062) already exists
failure adding node NodeData(nodeid:NumericNodeId(i=3062))
Traceback (most recent call last):
  File "Z:/Tin/python/experiment/server.py", line 13, in <module>
    server.import_xml("Z:/Tin/python/xml/Opc.Ua.NodeSet2.xml")
  File "Z:\python-opcua\opcua\server\server.py", line 523, in import_xml
    return importer.import_xml(path, xmlstring)
  File "Z:\python-opcua\opcua\common\xmlimporter.py", line 67, in import_xml
    node = self._add_node_data(nodedata)
  File "Z:\python-opcua\opcua\common\xmlimporter.py", line 82, in _add_node_data
    node = self.add_object(nodedata)
  File "Z:\python-opcua\opcua\common\xmlimporter.py", line 183, in add_object
    res[0].StatusCode.check()
  File "Z:\python-opcua\opcua\ua\uatypes.py", line 233, in check
    raise UaStatusCodeError(self.value)
opcua.ua.uaerrors._auto.BadNodeIdExists: The requested node id is already used by another node.(BadNodeIdExists)

I've been trying to figure out how I can import those xml files. I'm glad over any help.

@oroulet
Copy link
Member

oroulet commented Oct 13, 2018

Not being able to import NodeSet2 is completely normal. It is already imported. Concerning the other one either it is a bug or it requires another nodeset before

@NNTin
Copy link
Author

NNTin commented Oct 19, 2018

Thanks for clarifying regarding NodeSet2.

How would I import Opc.Ua.Fdi5.NodeSet2.xml?

In SiOME I would first import Opc.Ua.Di.NodeSet2.xml and then Opc.Ua.Fdi5.NodeSet2.xml.

When I do:

self.server.import_xml("Z:/Tin/python/xml/Opc.Ua.Di.NodeSet2.xml")
self.server.import_xml("Z:/Tin/python/xml/Opc.Ua.Fdi5.NodeSet2.xml")

I'm getting: The parent node id does not to refer to a valid node.(BadParentNodeIdInvalid)

Di.NodeSet2 is built on top of NodeSet2. Fdi5.Nodeset2 is built on top of Di.NodeSet2.

Is there a different method for importing multiple xmls?

@oroulet
Copy link
Member

oroulet commented Oct 19, 2018

the code above is correct, might be a bug in importer.... you are welcome to try to find out. Unfortumately the code is hard to understand...If someone has ideas to improve it , it would be great...

@PrudhviRajC
Copy link

Hallo @NNTin,
I am implementing the OPC UA Server and for that I want to import the XML file into it. When I import, I am also facing the same issue -
"raise UaStatusCodeError(self.value)
opcua.ua.uaerrors._auto.BadNodeIdExists: The requested node id is already used by another node.(BadNodeIdExists)".

Did you find any solution for this so far?
Thank you

@oroulet
Copy link
Member

oroulet commented Feb 24, 2019

BadNodeExist is clearly an issue with your setup or the XML file itself, not python-opcua code

@NNTin
Copy link
Author

NNTin commented Feb 24, 2019

My error code was different. The solution to my error was to import both models into SiOME and then export it as a single xml file.

I don't know if this solves your problem. Best of luck!

edit:
The error we share was solved by this comment:

Not being able to import NodeSet2 is completely normal. It is already imported.

As in I didn't need to import NodeSet2.

@NNTin NNTin changed the title server.import_xml leading to BadParentNodeIdInvalid or BadNodeIdExists server.import_xml leading to BadParentNodeIdInvalid Feb 24, 2019
@PrudhviRajC
Copy link

Sorry, I pasted the message wrong.
Its
"raise UaStatusCodeError(self.value)
opcua.ua.uaerrors._auto.BadParentNodeIdInvalid: The parent node id does not to refer to a valid node.(BadParentNodeIdInvalid)"

error bad parent node

@oroulet
Copy link
Member

oroulet commented Feb 27, 2019

I just found and fixed two bugs in apcua-asyncio. they should be backported to python-opcua

FreeOpcUa/opcua-asyncio@4b85a3f
and
FreeOpcUa/opcua-asyncio@681bcd6

Can someone do it?

@oroulet
Copy link
Member

oroulet commented Feb 27, 2019

BUT we now add a default reference type when no reference type is specified. I have no idea what the defalt should be. I used HasComponent, it might be wrong...

@anshi43
Copy link

anshi43 commented Jun 5, 2023

Hello guys,

I am also getting the same error as yours : raise UaStatusCodeError(self.value)
opcua.ua.uaerrors._auto.BadParentNodeIdInvalid: "The parent node id does not to refer to a valid node."(BadParentNodeIdInvalid)

i am trying to import all these files. custom_nodeset.xml was created using siemens SiOME modelling editor. here is the code :

import opcua

import time

from opcua import Server

import random

class OPCServer:

def init(self) :

self.server = Server()

def start(self):

self.server.set_server_name("OPC UA Server")

self.server.set_endpoint("opc.tcp://192.168.0.107:4140")

#self.server.import_xml("Opc.Ua.Di.Nodeset2.xml")

#self.server.import_xml("Opc.Ua.Machinery.Nodeset2.xml")

#self.server.import_xml("Opc.Ua.Pumps.Nodeset2.xml")

self.server.import_xml("custom_nodeset.xml")

self.server.start()

if name == 'main':

server = OPCServer()

server.start()

#server.run()

How did you guys solve this error?
your comments and advice would be appreciated.

@schroeder-
Copy link
Contributor

See #1475 . Switch to asyncua

@anshi43
Copy link

anshi43 commented Jun 5, 2023

See #1475 . Switch to asyncua

i tried but the error remain same

@anshi43
Copy link

anshi43 commented Jun 6, 2023

Sorry, I pasted the message wrong. Its "raise UaStatusCodeError(self.value) opcua.ua.uaerrors._auto.BadParentNodeIdInvalid: The parent node id does not to refer to a valid node.(BadParentNodeIdInvalid)"

error bad parent node

did you find the solution because i am getting the same error ?

@AndreasHeine
Copy link
Member

AndreasHeine commented Jun 6, 2023

the error tells you that the parent already exist! the nodeset ia already part of the default addreassspace.

edit:

you should use asyncua instead of this repo its depricated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants