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

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

Open
harriv opened this issue Oct 3, 2024 · 5 comments
Open

Comments

@harriv
Copy link
Contributor

harriv commented Oct 3, 2024

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
Copy link
Contributor Author

harriv commented Oct 3, 2024

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

image

image

image

@harriv
Copy link
Contributor Author

harriv commented Oct 29, 2024

I took another look at this.

Asyncua expects the relative path to have some content:

image

But the query actually has zero elements in relative path:

image

It is TranslateBrowsePathsToNodeIds which fails: https://reference.opcfoundation.org/Core/Part4/v104/docs/5.8.4

@harriv
Copy link
Contributor Author

harriv commented Oct 29, 2024

Investigating further, based on table 48 here: https://reference.opcfoundation.org/Core/Part4/v104/docs/5.8.4 - BadNothingToDo should be returned if relativePath is empty list. Adding this however didn't solve the problem.

Tested also with Prosys OPC UA Simulation server, it worked fine.

@schroeder-
Copy link
Contributor

relativePath can't be empty.
From the specs:
The path to follow from the startingNode.The last element in the relativePath shall always have a targetName specified. This further restricts the definition of the RelativePath type. The Server shall return Bad_BrowseNameInvalid if the targetName is missing.The RelativePath structure is defined in 7.26.

So we should return Bad_BrowseNameInvalid.

@schroeder-
Copy link
Contributor

Ok BadNothingToDo is the result. This is a bit misleading in the spec.

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

2 participants