FreeOpcUa / python-opcua

LGPL Pure Python OPC-UA Client and Server
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
1.35k stars 658 forks source link

load_type_definitions() method can't load custom enum structure #1283

Open sofaboss opened 3 years ago

sofaboss commented 3 years ago

Hello everybody,

I am developing an OPC UA client in order to access the OPC UA server/client of B&R Automation Studio 4.9.2 ("B&R Embedded OPC-UA Server and Client")

It seems like the method load_type_definitions() struggles with the custom structures because it throws this error:

File "C:\Python37\lib\site-packages\opcua\client\client.py", line 620, in load_type_definitions
    return load_type_definitions(self, nodes)
  File "C:\Python37\lib\site-packages\opcua\common\structures.py", line 265, in load_type_definitions
    generator.get_python_classes(structs_dict)
  File "C:\Python37\lib\site-packages\opcua\common\structures.py", line 202, in get_python_classes
    return _generate_python_class(self.model, env=env)
  File "C:\Python37\lib\site-packages\opcua\common\structures.py", line 329, in _generate_python_class
    exec(code, env)
  File "<string>", line 3
    class MpAudit.MpAuditErrorEnum(IntEnum):
                 ^
SyntaxError: invalid syntax

To reproduce this issue you need to install Automation Studio 4.9.2 - Direct Link or Download-Overview and a simple client with:

client = Client("opc.tcp://127.0.0.1:4840")
client.load_type_definitions()

Unfortunately I can't modify these structures in the server. Is it possible to ignore specific nodes?

Used versions:

oroulet commented 3 years ago

There is a clean_name or simlar function somewhere in code that obvisouly orgets to remove empty spaces in some struct name... you can try opcua-asyncio and hopefully it does not have that bus