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

Handling all possible opcua exceptions using freeopcua #1329

Closed
rajnishnationfirst opened this issue May 30, 2021 · 7 comments
Closed

Handling all possible opcua exceptions using freeopcua #1329

rajnishnationfirst opened this issue May 30, 2021 · 7 comments

Comments

@rajnishnationfirst
Copy link

rajnishnationfirst commented May 30, 2021

Hi team ,

I want to handle the below exceptions using python opcua exceptions like below .

1) BadSessionIdInvalid 
2) BadSessionNotActivated
3)BadTooManyOperations
4) BadSessionIdInvalid

suppose i get the exceptions as :

a) opcua.ua.uaerrors._auto.BadTooManyOperations: The request could not be processed because it specified too many operations.(BadTooManyOperations)

AND

b) opcua.ua.uaerrors._auto.BadSessionIdInvalid: The session id is not valid.(BadSessionIdInvalid)

try:
    ..... code

except (BadSessionIdInvalid ,BadSessionNotActivated,BadTooManyOperations,BadSessionIdInvalid) as errors:
     ....code 

Need help for the handling the exceptions . Request anyone to help with your replies for below questions.

  1. Any base class to handle all exceptions of opcua.

It will be great help of me if any one can assist the same .

Rajnish Vishwakarma

@AndreasHeine
Copy link
Member

not an issue!

@oroulet
Copy link
Member

oroulet commented May 31, 2021

also if someone comes here the correct syntax is.

try: 
   mys ua code
except ua.UaError:
    do something

this will catch all errors from protocol

@rajnishnationfirst
Copy link
Author

rajnishnationfirst commented Sep 8, 2022

Hi Oroulet ,

Thanks a lot for your kind support for me as i have been very new to OPC UA protocol usage.

If i have to receive all possible exceptions for a client-minimal.py example of free-opcua python , is the below code correct to catch all the possible exceptions occurring mentioned above in my first post to this discussion :

1) BadSessionIdInvalid
2) BadSessionNotActivated
3) BadTooManyOperations
4) BadSessionIdInvalid

Is the below code correct for all exceptions mentioned above ?

class SubHandler():

    try: 
          def datachange_notification(self, node, val, data):
               print(datetime.now(), "- Data Change - ", val)
  
          def event_notification(self, event):
              pass

    except ua.UaError:
          do something like reconnect or resuscribe or etc

Thanks

Rajnish Vishwakarma

@swamper123
Copy link
Contributor

If you are excepting UaError you may get one of those:

https://github.com/FreeOpcUa/python-opcua/blob/858274721766907148b527916e97446dbbf6af6d/opcua/ua/uaerrors/_auto.py

Since stuff can change, you can't guarantee that just those 4 will occur.

@swamper123
Copy link
Contributor

And I guess you are aware of #1475 ?!

@rajnishnationfirst
Copy link
Author

rajnishnationfirst commented Sep 8, 2022

Thanks @swamper123 for your reply.

yes agreed . Could you pls let me know whether the below code for handling all possible exceptions is correct for a
client-minimal.py example in the freeo-pcua python example list?

Code is as follows :

**Is the below code correct for handling all exceptions in client-minimal.py example mentioned in the freeo-pcua python example list ** ?

class SubHandler():

    try: 
          def datachange_notification(self, node, val, data):
               print(datetime.now(), "- Data Change - ", val)
  
          def event_notification(self, event):
              pass

    except ua.UaError:
          do something like reconnect or resuscribe or etc

Thanks

Rajnish Vishwakarma

@swamper123
Copy link
Contributor

The code you are posting seems to handle UaErrors.
Follow the link in my first answer to see, what is expected what a server may return.

I can't say if this list is uptodate, since this library is deprecated and not sure if even the nodeset from asyncua is uptodate atm.
It is possible that more errors may be possible.

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

4 participants