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

SyntaxError: invalid syntax. Perhaps you forgot a comma? uaclient.mainwindow - WARNING - showing error: %s')` #83

Open
mukaraT opened this issue Jun 8, 2022 · 5 comments

Comments

@mukaraT
Copy link

mukaraT commented Jun 8, 2022

I tried to connect with my simeens PLC OPC Server via this opcua python gui client, but unfortunately it is throwing the below error! Any idea how to fix it?

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Mukara> & d:/Thangz/Projekte/VC/python_venv/.python_venv/Scripts/Activate.ps1
(.python_venv) PS C:\Users\Mukara> opcua-client
pyqtgraph or numpy are not installed, use of graph feature disabled
ADR ['opc.tcp://localhost:4840', 'opc.tcp://localhost:53530/OPCUA/SimulationServer/']
(.python_venv) PS C:\Users\Mukara> opcua-client
ADR ['opc.tcp://localhost:4840', 'opc.tcp://localhost:53530/OPCUA/SimulationServer/']
uaclient.uaclient - INFO - Connecting to opc.tcp://localhost:4840 with parameters None, None, None, None')
uaclient.mainwindow - WARNING - showing error: %s')
uawidgets.utils - ERROR - ')
Traceback (most recent call last):
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 960, in _connect_sock     
    await self.sock_connect(sock, address)
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 705, in sock_connect  
    return await self._proactor.connect(sock, address)
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\uawidgets\utils.py", line 21, in wrapper
    result = func(self, *args)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\uaclient\mainwindow.py", line 354, in connect
    self.uaclient.connect(uri)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\uaclient\uaclient.py", line 124, in connect
    self.client.connect()
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\sync.py", line 94, in wrapper
    result = self.tloop.post(aio_func(*args, **kwargs))
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\sync.py", line 52, in post
    return futur.result()
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 446, in result
    return self.__get_result()
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result
    raise self._exception
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\client\client.py", line 252, in connect
    await self.connect_socket()
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\client\client.py", line 279, in connect_socket
    await self.uaclient.connect_socket(self.server_url.hostname, self.server_url.port)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\client\ua_client.py", line 266, in connect_socket
    await asyncio.wait_for(asyncio.get_running_loop().create_connection(self._make_protocol, host, port), self._timeout)
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
uaclient.mainwindow - WARNING - showing error: %s')
uaclient.uaclient - INFO - Connecting to opc.tcp://localhost:4840 with parameters None, None, None, None')
asyncua.client.client - WARNING - Requested session timeout to be 3600000ms, got 30000ms instead')
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
asyncua.common.structures104 - WARNING - renamed "random_number_generator"."4210_30M1Pos" to _random_number_generator_4210_30M1Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "random_number_generator"."4215_30M1Pos" to _random_number_generator_4215_30M1Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V02Msg"."4180Info" to _V02Msg_4180Info_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V02Msg"."4185Info" to _V02Msg_4185Info_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V02Msg"."4177Info" to _V02Msg_4177Info_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_RcpBufferTank"."CoolStep" to _U_RcpBufferTank_CoolStep_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20ProdPl"."4160" to _V20ProdPl_4160_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20ProdPl"."4165" to _V20ProdPl_4165_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V01WRcp"."4160" to _V01WRcp_4160_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V01WRcp"."4165" to _V01WRcp_4165_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Mp"."4215_30M1Pos" to _V20Mp_4215_30M1Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Mp"."4210_30M1Pos" to _V20Mp_4210_30M1Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Mp"."4220_30M1Pos" to _V20Mp_4220_30M1Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Mp"."4215_30M11Pos" to _V20Mp_4215_30M11Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Mp"."4225_30M1Pos" to _V20Mp_4225_30M1Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Mp"."4225_30M11Pos" to _V20Mp_4225_30M11Pos_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."BTFillingDone" to _V20BatchData_BTFillingDone_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."4185MoRU" to _V20BatchData_4185MoRU_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."4180MoLU" to _V20BatchData_4180MoLU_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."4185MoLU" to _V20BatchData_4185MoLU_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."4180MoRU" to _V20BatchData_4180MoRU_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."BTFillingStart" to _V20BatchData_BTFillingStart_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."BTEmptDone" to _V20BatchData_BTEmptDone_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."BTEmptStart" to _V20BatchData_BTEmptStart_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20BatchData"."BTFillingStart"."Data" to _V20BatchData_BTFillingStart_Data_ due to Python syntax')asyncua.common.structures104 - WARNING - renamed "V20BatchData"."BTEmptDone"."Data" to _V20BatchData_BTEmptDone_Data_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3CipToMG1"."Gen" to _U_Ex3CipToMG1_Gen_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3CipToMG1"."Prod" to _U_Ex3CipToMG1_Prod_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3CipToMG1"."CIP" to _U_Ex3CipToMG1_CIP_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3CipToMG1"."CIP"."Gen" to _U_Ex3CipToMG1_CIP_Gen_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3MG1ToCip"."Gen" to _U_Ex3MG1ToCip_Gen_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3MG1ToCip"."Prod" to _U_Ex3MG1ToCip_Prod_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3MG1ToCip"."Cip" to _U_Ex3MG1ToCip_Cip_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex3MG1ToCip"."Cip"."Gen" to _U_Ex3MG1ToCip_Cip_Gen_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex1DeKlogslagToMG1"."MoIn" to _U_Ex1DeKlogslagToMG1_MoIn_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex1DeKlogslagToMG1"."MoOut" to _U_Ex1DeKlogslagToMG1_MoOut_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex1MG1ToDeKlogslag"."MoIn" to _U_Ex1MG1ToDeKlogslag_MoIn_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex1MG1ToDeKlogslag"."MoOut" to _U_Ex1MG1ToDeKlogslag_MoOut_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex2MG1ToTeco"."Prod" to _U_Ex2MG1ToTeco_Prod_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex2MG1ToTeco"."Prod"."BT" to _U_Ex2MG1ToTeco_Prod_BT_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex2TecoToMG1"."Prod" to _U_Ex2TecoToMG1_Prod_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_Ex2TecoToMG1"."Prod"."BT" to _U_Ex2TecoToMG1_Prod_BT_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "V20Reg"."Loupe" to _V20Reg_Loupe_ due to Python syntax')
asyncua.common.structures104 - WARNING - renamed "U_RegLoupeDataMG1"."Data" to _U_RegLoupeDataMG1_Data_ due to Python syntax')
asyncua.common.structures104 - ERROR - Failed to execute auto-generated code from UA datatype: 

@dataclass
class U_StB1:

    '''
    U_StB1 structure autogenerated from StructureDefinition object
    '''

    data_type = ua.NodeId.from_string("ns=3;s=DT_"U_StB1"")

    Alm: ua.Boolean = True
    RstAlm: ua.Boolean = True
')
Traceback (most recent call last):
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\common\structures104.py", line 277, in _generate_object
    exec(code, env)
  File "<string>", line 10
    data_type = ua.NodeId.from_string("ns=3;s=DT_"U_StB1"")
                                      ^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
uaclient.mainwindow - WARNING - showing error: %s')
uawidgets.utils - ERROR - invalid syntax. Perhaps you forgot a comma? (<string>, line 10)')
Traceback (most recent call last):
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\uawidgets\utils.py", line 21, in wrapper
    result = func(self, *args)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\uaclient\mainwindow.py", line 354, in connect
    self.uaclient.connect(uri)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\uaclient\uaclient.py", line 126, in connect
    self.client.load_data_type_definitions()
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\sync.py", line 94, in wrapper
    result = self.tloop.post(aio_func(*args, **kwargs))
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\sync.py", line 52, in post
    return futur.result()
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 446, in result
    return self.__get_result()
  File "C:\Users\Mukara\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result
    raise self._exception
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\client\client.py", line 685, in load_data_type_definitions
    return await load_data_type_definitions(self, node, overwrite_existing=overwrite_existing)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\common\structures104.py", line 356, in load_data_type_definitions  
    env = await _generate_object(dts.name, dts.sdef, data_type=dts.data_type)
  File "D:\Thangz\Projekte\VC\python_venv\.python_venv\lib\site-packages\asyncua\common\structures104.py", line 277, in _generate_object
    exec(code, env)
  File "<string>", line 10
    data_type = ua.NodeId.from_string("ns=3;s=DT_"U_StB1"")
                                      ^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
uaclient.mainwindow - WARNING - showing error: %s')

Regards,
Mukara

@schroeder-
Copy link

What Version of asyncua you have installed?
Looks like this issue: FreeOpcUa/opcua-asyncio#813

@mukaraT
Copy link
Author

mukaraT commented Jun 8, 2022

I just installed the latest version via PIP!

D:\Thangz\Projekte\VC\python_venv.python_venv\Lib\site-packages\asyncua\ua\uatypes.py is already up-to-date:

.
.
.



@dataclass(frozen=True, init=False, order=True)
class QualifiedName:
    """
    A string qualified with a namespace index.
    """

    NamespaceIndex: UInt16 = 0
    Name: String = ""

    def __init__(self, Name=None, NamespaceIndex=0):
        object.__setattr__(self, "Name", Name)
        object.__setattr__(self, "NamespaceIndex", NamespaceIndex)
        if isinstance(self.NamespaceIndex, str) and isinstance(self.Name, int):
            # originally the order or argument was inversed, try to support it
            logger.warning("QualifiedName are str, int, while int, str is expected, swithcing")

        if not isinstance(self.NamespaceIndex, int) or not isinstance(self.Name, (str, type(None))):
            raise ValueError(f"QualifiedName constructore args have wrong types, {self}")

    def to_string(self):
        return f"{self.NamespaceIndex}:{self.Name}"

    @staticmethod
    def from_string(string):
        if ":" in string:
            try:
                idx, name = string.split(":", 1)
                idx = int(idx)
            except (TypeError, ValueError) as ex:
                raise UaStringParsingError(f"Error parsing string {string}", ex) from ex
        else:
            idx = 0
            name = string
        return QualifiedName(Name=name, NamespaceIndex=idx)

.
.
.

@schroeder-
Copy link

There is a open pr: FreeOpcUa/opcua-asyncio#784
Maybe you can test it.

@mukaraT
Copy link
Author

mukaraT commented Jun 8, 2022

FYI this is my code which I am testing:

from opcua import Client, ua

def browse_recursive(node):
    for childId in node.get_children():
        ch = client.get_node(childId)
        print(ch.get_node_class())
        if ch.get_node_class() == ua.NodeClass.Object:
            browse_recursive(ch)
        elif ch.get_node_class() == ua.NodeClass.Variable:
            try:
                print("{bn} has value {val}".format(
                    bn=ch.get_browse_name(),
                    val=str(ch.get_value()))
                )
            except ua.uaerrors._auto.BadWaitingForInitialData:
                pass
            
if __name__ == "__main__":
    client = Client("opc.tcp://localhost:4840")
    try:
        client.connect()
        root = client.get_root_node()
        print("Objects root node is: ", root)
        browse_recursive(root)
    finally:
        client.disconnect()

@oroulet
Copy link
Member

oroulet commented Jun 8, 2022

You plc has node name with " inside their name. That beaks python syntax.

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

3 participants