FreeOpcUa / opcua-asyncio

OPC UA library for python >= 3.7
GNU Lesser General Public License v3.0
1.12k stars 361 forks source link

Error "list index out of range" when calling method in server-methods.py #1716

Open harriv opened 2 weeks ago

harriv commented 2 weeks ago

Describe the bug

When calling mulptily method in examples/server-methods.py from OPC Router (https://opc-router.com), following error message is created:

INFO:asyncua.server.uaprocessor:Read request (User(role=<UserRole.User: 3>, name=None))
DEBUG:asyncua.server.binary_server_asyncio:_process_received_message 57 57
DEBUG:asyncua.server.uaprocessor:process_message NodeId(Identifier=554, NamespaceIndex=0, NodeIdType=<NodeIdType.FourByte: 1>) RequestHeader(AuthenticationToken=NodeId(Identifier=1005, NamespaceIndex=0, NodeIdType=<NodeIdType.FourByte: 1>), Timestamp=datetime.datetime(2024, 10, 3, 11, 47, 20, 83604, tzinfo=datetime.timezone.utc), RequestHandle=22, ReturnDiagnostics=0, AuditEntryId=None, TimeoutHint=0, AdditionalHeader=ExtensionObject(TypeId=NodeId(Identifier=0, NamespaceIndex=0, NodeIdType=<NodeIdType.TwoByte: 0>), Body=None))
INFO:asyncua.server.uaprocessor:translate browsepaths to nodeids request (User(role=<UserRole.User: 3>, name=None))
ERROR:asyncua.server.uaprocessor:Error while processing message
Traceback (most recent call last):
  File "D:\Projektit\test\OMA_test\venv\Lib\site-packages\asyncua\server\uaprocessor.py", line 143, in process_message
    return await self._process_message(typeid, requesthdr, seqhdr, body)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projektit\test\OMA_test\venv\Lib\site-packages\asyncua\server\uaprocessor.py", line 319, in _process_message
    paths = await self.session.translate_browsepaths_to_nodeids(params.BrowsePaths)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projektit\test\OMA_test\venv\Lib\site-packages\asyncua\server\internal_session.py", line 184, in translate_browsepaths_to_nodeids
    return self.iserver.view_service.translate_browsepaths_to_nodeids(params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projektit\test\OMA_test\venv\Lib\site-packages\asyncua\server\address_space.py", line 188, in translate_browsepaths_to_nodeids
    results.append(self._translate_browsepath_to_nodeid(path))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projektit\test\OMA_test\venv\Lib\site-packages\asyncua\server\address_space.py", line 194, in _translate_browsepath_to_nodeid
    if not path.RelativePath.Elements[-1].TargetName:
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

UaExpert works fine with this method, so there might be also implementation problem in the OPC Router, but I'm not familiar enough with the library and protocol to tell what is happening.

To Reproduce
Steps to reproduce the behavior incl code:

  1. Run server-methods.py
  2. Call mulptiply method from OPC Router

Expected behavior
A clear and concise description of what you expected to happen.

Method returns the correct value with out no errors.

Version
Python-Version: 3,12.5
opcua-asyncio Version (e.g. master branch, 0.9): 1.1.5

harriv commented 2 weeks ago

I took a look with WireShark, OPC Router does TranslateBrowsePathsToNodeIdsRequest, which UaExpert doens't do:

image

image

image