FreeOpcUa / python-opcua

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

Unable to read data from node. Throwing opcua.ua.uaerrors._auto.Bad: The operation failed.(Bad) error. #1145

Open sb934 opened 4 years ago

sb934 commented 4 years ago

I am trying to read data from a Kepware server at regular intervals. I am able to read some tags in the address space; however some tags end up giving me a _opcua.ua.uaerrors.auto.Bad: The operation failed.(Bad) error. So I included a try/catch so that the code is not interrupted, skips the tags throwing Bad StatusCode. Check the following output (of 1 iteration)...

Node1: 333

ua.uaerrors._auto.Bad @ Node2 ua.uaerrors._auto.Bad @ Node3

Node4 : 0

Node5 : 1

Node6 : 9

Node7 : False

Something that doesn't add up is that if I open these Nodes (1,2,3) in UAExpert, the Python script is suddenly able to read values for those nodes too (like Node1 above). It takes a few seconds for UAExpert to get Good StatusCode for these nodes. (BadInitialWaiting -> Bad -> Good) . Similarly, if I close UAExpert the Python script starts catching Bad error on these nodes again...

Is there a way I can repeatedly try reading a node value, before moving on to the next line of code? Or any other workaround this issue?

AndreasHeine commented 4 years ago

try reading if status is not good raise error/except pass in a while loop and if reading is good break!?

but tbh its ugly 😬

sb934 commented 4 years ago

I have my Node Details in a JSON file. This is what I am doing...

if(len(config['Tags'])):

    for obj in config['Tags']:

        try:

            node = client.get_node(obj['node_addr'])

            node_value = node.get_value()

            print(obj['tag'],':',str(node_value),'\n')

            v1 = [obj['tag'],str(node_value),obj['msg_type'],0]

            push_value(c, v1)

        except ua.uaerrors._auto.BadWaitingForInitialData:

            print("ua.uaerrors._auto.BadWaitingForInitialData @ ", obj['tag'])

            #pass 
        except ua.uaerrors._auto.Bad:

            print("ua.uaerrors._auto.Bad @ ", obj['tag'])

            #pass
else:

    print("No Tags to retrieve from server")

This reads the remaining nodes. But Node 1,2,3 aren't readable even after multiple iterations.

AndreasHeine commented 4 years ago

can you post a screenshot from ua expert of those nodes (addressspace and attributes)? have you tryed to subscribe the nodes, instead of polling, to get the data it much simpler because you will get a datachange notification if the node value change!?

sb934 commented 4 years ago

image

image

image

image

As mentioned earlier: As soon as I open these tags in UAExpert. The Python script is able to read values without any exceptions. Attaching a screenshot for your reference.

sb934 commented 4 years ago

@AndreasHeine you got anything mate?

AndreasHeine commented 4 years ago

sorry took some sleep guess your in a different timezon 🤔

AndreasHeine commented 4 years ago

try browse them before reading value!!?

AndreasHeine commented 4 years ago

success?

sb934 commented 4 years ago

If I use the subscriber class instead of manually reading the value, it throws the same "Bad Status" error. I can try again though. Didn't get you on the browsing part..?

sb934 commented 4 years ago

What I don't understand is that how is UAExpert and Python script connected? Like why does the code stop giving me errors and starts reading the value as soon as I start reading the same nodes in UAExpert?

AndreasHeine commented 4 years ago

just call node.get_browse_name() before you subscribe or read the node! there was something in the past but i can hardly remember... not sure if it was with kepware.

LostInDarkMath commented 3 years ago

I have exactly the same problem as @sb934. The suggested solution from @AndreasHeine does not work for me. Does someone have an idea how I can fix this?

zerox1212 commented 3 years ago

Sorry, best answer I can give is to avoid using Kepware. The server is notoriously bad.

LostInDarkMath commented 3 years ago

Are there any alternatives to Kepware that you would recommend?

AndreasHeine commented 3 years ago

the thing with the the statuscode of kepware tags is it is dependend on the connectionstatus from kepware to the datahost... had this in a prev project the only thing you can do is to react to the bad statuscodes and try to browse the tags up front most of the time it helps otherweise it depends on the driver in kepware when it starts to update the opc ua tags...

yetkinakyz commented 2 years ago

Hi there, I have the same problem that I cannot read some nodes from Sinumerik 840D opcua server and get 'Operation failed.(Bad)' error. Also, I can read all nodes with Prosys opcua client. Did you find any solution?

KenSense commented 1 year ago

I have the same problem with SINUMERIK OPC UA Server. One specific node doesn't want to be read. /Tool/Catalogue/toolIdent[u1,49] it's the last one of a list.

That's the same error as if I go one index too far in another working list. UaExpert doesn't give an error I can read whatever index I want out of range and it will still say it's ok without return value.

FailedRead
schroeder- commented 1 year ago

As you see UAExpert can only read it via Subscription, but not via ReadRequest. So this is something the SINUMERIK OPC UA Server doesn't support and not the error of this library.

KenSense commented 1 year ago

I can indeed subscribe to it, Thanks. New data change event ns=2;s=/Tool/Catalogue/toolIdent[u1,49] None