opcua-asyncio
opcua-asyncio copied to clipboard
Unable to find all nodes by ua_utils.get_node_children()
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())
//////////////////////////////
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?
Also i noticed your screenshot doesn't match you posted code. Is objects == client.nodes.objects
?
Also i noticed your screenshot doesn't match you posted code. Is
objects == client.nodes.objects
?
yes, objects = client.nodes.objects
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
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)
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:
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:
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.
Hello again
There is a new problem, to collecting the values an error happened "asyncua.common.utils.NotEnoughData"
The decoding of a value fails, maybe it is needed to load custom datatypes:
await client.load_data_type_definitions()
The decoding of a value fails, maybe it is needed to load custom datatypes:
await client.load_data_type_definitions()
Still same error ...