opcua-asyncio icon indicating copy to clipboard operation
opcua-asyncio copied to clipboard

Unable to find all nodes by ua_utils.get_node_children()

Open omidfathi opened this issue 2 years ago • 10 comments

Hi I want to connect to Prosys opcua server simulation, and i need to find all nodes on server.so i use ua_utils.get_node_children(client.nodes.objects) but I get this error: 'NoneType' object has no attribute 'send_request'

//////////////////////////////

import logging
import asyncio

from asyncua import Client , Node ,ua
from asyncua.common import ua_utils
async def main():
    client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
    client.session_timeout = 2000
    root = client.nodes.root
    while True:
            allVariables = []
            node_List = await ua_utils.get_node_children(client.nodes.objects)
            for i in node_List:
                nodeClass = await i.read_node_class()
                if nodeClass == ua.NodeClass.Variable:
                        allVariables.append(n)
            print(allVariables)
            await asyncio.sleep(1)

if __name__ == "__main__":
    logging.basicConfig(level=logging.WARN)
    asyncio.run(main())

//////////////////////////////

Screenshot from 2022-06-27 17-45-34

omidfathi avatar Jun 27 '22 13:06 omidfathi

I tested get_node_children against our server it is working correct. As I don't have access to a Prosys OPC UA Simulation Server, can you provide a extended stack trace or debug log?

schroeder- avatar Jun 28 '22 08:06 schroeder-

Also i noticed your screenshot doesn't match you posted code. Is objects == client.nodes.objects ?

schroeder- avatar Jun 28 '22 08:06 schroeder-

Also i noticed your screenshot doesn't match you posted code. Is objects == client.nodes.objects ?

yes, objects = client.nodes.objects

omidfathi avatar Jun 28 '22 08:06 omidfathi

I tested get_node_children against our server it is working correct. As I don't have access to a Prosys OPC UA Simulation Server, can you provide a extended stack trace or debug log?


Connected to pydev debugger (build 221.5921.27)
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/ofathi/PycharmProjects/pythonProject1/main.py", line 45, in main
    nodelist = await ua_utils.get_node_children(objects)
  File "/home/ofathi/PycharmProjects/pythonProject1/venv/lib/python3.10/site-packages/asyncua/common/ua_utils.py", line 157, in get_node_children
    for child in await node.get_children():
  File "/home/ofathi/PycharmProjects/pythonProject1/venv/lib/python3.10/site-packages/asyncua/common/node.py", line 348, in get_children
    return await self.get_referenced_nodes(refs, ua.BrowseDirection.Forward, nodeclassmask)
  File "/home/ofathi/PycharmProjects/pythonProject1/venv/lib/python3.10/site-packages/asyncua/common/node.py", line 421, in get_referenced_nodes
    references = await self.get_references(refs, direction, nodeclassmask, includesubtypes)
  File "/home/ofathi/PycharmProjects/pythonProject1/venv/lib/python3.10/site-packages/asyncua/common/node.py", line 401, in get_references
    results = await self.server.browse(params)
  File "/home/ofathi/PycharmProjects/pythonProject1/venv/lib/python3.10/site-packages/asyncua/client/ua_client.py", line 342, in browse
    data = await self.protocol.send_request(request)
AttributeError: 'NoneType' object has no attribute 'send_request'

Process finished with
``` exit code 1

omidfathi avatar Jun 28 '22 08:06 omidfathi

Ok the problem is you did not connect to the server.

async def main():
    client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
    client.session_timeout = 2000
    root = client.nodes.root
    async with client:
      allVariables = []
      node_List = await ua_utils.get_node_children(client.nodes.objects)
      for i in node_List:
          nodeClass = await i.read_node_class()
          if nodeClass == ua.NodeClass.Variable:
                  allVariables.append(n)
      print(allVariables)
      await asyncio.sleep(1)

schroeder- avatar Jun 28 '22 08:06 schroeder-

I tested get_node_children against our server it is working correct. As I don't have access to a Prosys OPC UA Simulation Server, can you provide a extended stack trace or debug log?

This is debug log: Screenshot from 2022-06-28 13-10-34

omidfathi avatar Jun 28 '22 08:06 omidfathi

I tested get_node_children against our server it is working correct. As I don't have access to a Prosys OPC UA Simulation Server, can you provide a extended stack trace or debug log?

This is debug log: Uploading Screenshot from 2022-06-28 13-10-34.png…

Ok the problem is you did not connect to the server.

async def main():
    client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
    client.session_timeout = 2000
    root = client.nodes.root
    async with client:
      allVariables = []
      node_List = await ua_utils.get_node_children(client.nodes.objects)
      for i in node_List:
          nodeClass = await i.read_node_class()
          if nodeClass == ua.NodeClass.Variable:
                  allVariables.append(n)
      print(allVariables)
      await asyncio.sleep(1)

What a clear mistake !!! Sorry to take your time ... It's work now.

omidfathi avatar Jun 28 '22 08:06 omidfathi

Hello again

There is a new problem, to collecting the values an error happened "asyncua.common.utils.NotEnoughData" Screenshot from 2022-06-29 11-30-49

omidfathi avatar Jun 29 '22 07:06 omidfathi

The decoding of a value fails, maybe it is needed to load custom datatypes: await client.load_data_type_definitions()

schroeder- avatar Jun 29 '22 07:06 schroeder-

The decoding of a value fails, maybe it is needed to load custom datatypes: await client.load_data_type_definitions()

Still same error ...

omidfathi avatar Jun 29 '22 10:06 omidfathi