Giter Site home page Giter Site logo

issue about python-opcua HOT 8 CLOSED

freeopcua avatar freeopcua commented on August 22, 2024
issue

from python-opcua.

Comments (8)

oroulet avatar oroulet commented on August 22, 2024 1

ok . Now I think I understand. The server break the connection and sends an
incomplete packet. I will have a look if I can add a try catch around that
or raise the exception in client thread

On Fri, 7 Aug 2015 at 16:03 Olivier Roulet-Dubonnet <
[email protected]> wrote:

Obviously when I restart a server here I do not get that kind of error.
Kan you send me a reproductible scenario?

On Fri, 7 Aug 2015 at 16:01 kashp [email protected] wrote:

yes when you restart OPC server

On Client side these error started, I want to re initialize connection
but due to absence of raise condition i can not handle any Broken
connection exception

I also received

Traceback (most recent call last):
File "/home/kashp/PycharmProjects/gor_flip/OpcuaConnection.py", line 42,
in write_tag
var = self.root.get_child(["0:Objects", read_path])
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 290, in
get_child
result = self.server.translate_browsepaths_to_nodeids([bpath])
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
292, in translate_browsepaths_to_nodeids
data = self._send_request(request)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
60, in _send_request
self._write_socket(hdr, symhdr, seqhdr, request)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
141, in _write_socket
self._socket.write(alle)
File "/home/kashp/PycharmProjects/gor_flip/opcua/utils.py", line 88, in
write
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

Traceback (most recent call last):
File "/home/kashp/PycharmProjects/gor_flip/OpcuaConnection.py", line 43,
in write_tag
var.set_value(dv)
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 187, in
set_value
self.set_attribute(ua.AttributeIds.Value, datavalue)
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 200, in
set_attribute
result[0].check()
File "/home/kashp/PycharmProjects/gor_flip/opcua/uatypes.py", line 249,
in check
raise Exception("{}({})".format(self.doc, self.name))
Exception: The node id refers to a node that does not exist in the server
address space.(BadNodeIdUnknown)


Reply to this email directly or view it on GitHub
#21 (comment)
.

from python-opcua.

oroulet avatar oroulet commented on August 22, 2024

Do you have a reproductiblr scénario or is it à one time event?

On Fri, Aug 7, 2015, 14:28 kashp [email protected] wrote:

Hi
When Opc server restarted i got the following issue

File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 297, in
_invoke_callbacks
callback(self)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
328, in _call_publish_callback
response = ua.PublishResponse.from_binary(future.result())
File "/home/kashp/PycharmProjects/gor_flip/opcua/uaprotocol_auto.py", line
10434, in from_binary
obj.Parameters = PublishResult.from_binary(data)
File "/home/kashp/PycharmProjects/gor_flip/opcua/uaprotocol_auto.py", line
10383, in from_binary
obj.SubscriptionId = unpack_uatype('UInt32', data)
File "/home/kashp/PycharmProjects/gor_flip/opcua/uatypes.py", line 135, in
unpack_uatype
return struct.unpack(fmt, data.read(size))[0]
File "/home/kashp/PycharmProjects/gor_flip/opcua/utils.py", line 39, in
read
raise Exception("No enough data left in buffer, request for {}, we have
{}".format(size, self))
Exception: No enough data left in buffer, request for 4, we have
Buffer(size:0, data:b'')


Reply to this email directly or view it on GitHub
#21.

from python-opcua.

kashp avatar kashp commented on August 22, 2024

yes when you restart OPC server

On Client side these error started, I want to re initialize connection but due to absence of raise condition i can not handle any Broken connection exception

I also received

Traceback (most recent call last):
File "/home/kashp/PycharmProjects/gor_flip/OpcuaConnection.py", line 42, in write_tag
var = self.root.get_child(["0:Objects", read_path])
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 290, in get_child
result = self.server.translate_browsepaths_to_nodeids([bpath])
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line 292, in translate_browsepaths_to_nodeids
data = self._send_request(request)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line 60, in _send_request
self._write_socket(hdr, symhdr, seqhdr, request)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line 141, in _write_socket
self._socket.write(alle)
File "/home/kashp/PycharmProjects/gor_flip/opcua/utils.py", line 88, in write
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

Traceback (most recent call last):
File "/home/kashp/PycharmProjects/gor_flip/OpcuaConnection.py", line 43, in write_tag
var.set_value(dv)
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 187, in set_value
self.set_attribute(ua.AttributeIds.Value, datavalue)
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 200, in set_attribute
result[0].check()
File "/home/kashp/PycharmProjects/gor_flip/opcua/uatypes.py", line 249, in check
raise Exception("{}({})".format(self.doc, self.name))
Exception: The node id refers to a node that does not exist in the server address space.(BadNodeIdUnknown)

from python-opcua.

oroulet avatar oroulet commented on August 22, 2024

Obviously when I restart a server here I do not get that kind of error. Kan
you send me a reproductible scenario?

On Fri, 7 Aug 2015 at 16:01 kashp [email protected] wrote:

yes when you restart OPC server

On Client side these error started, I want to re initialize connection but
due to absence of raise condition i can not handle any Broken connection
exception

I also received

Traceback (most recent call last):
File "/home/kashp/PycharmProjects/gor_flip/OpcuaConnection.py", line 42,
in write_tag
var = self.root.get_child(["0:Objects", read_path])
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 290, in
get_child
result = self.server.translate_browsepaths_to_nodeids([bpath])
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
292, in translate_browsepaths_to_nodeids
data = self._send_request(request)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
60, in _send_request
self._write_socket(hdr, symhdr, seqhdr, request)
File "/home/kashp/PycharmProjects/gor_flip/opcua/binary_client.py", line
141, in _write_socket
self._socket.write(alle)
File "/home/kashp/PycharmProjects/gor_flip/opcua/utils.py", line 88, in
write
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

Traceback (most recent call last):
File "/home/kashp/PycharmProjects/gor_flip/OpcuaConnection.py", line 43,
in write_tag
var.set_value(dv)
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 187, in
set_value
self.set_attribute(ua.AttributeIds.Value, datavalue)
File "/home/kashp/PycharmProjects/gor_flip/opcua/node.py", line 200, in
set_attribute
result[0].check()
File "/home/kashp/PycharmProjects/gor_flip/opcua/uatypes.py", line 249, in
check
raise Exception("{}({})".format(self.doc, self.name))
Exception: The node id refers to a node that does not exist in the server
address space.(BadNodeIdUnknown)


Reply to this email directly or view it on GitHub
#21 (comment)
.

from python-opcua.

oroulet avatar oroulet commented on August 22, 2024

And I had one more look.....
There is no point in raising in exception there, this happens in a callback from the server. you have no method call where to raise an exception.
We could set a flag in the library but I am unsure if this is a good solution. you would nee to poll that flag....
I think if you want to detect if the connection is lost the best thing to do is to read a node value on the server at a given frequence. If the connection is lost an exception will read and you can restart client

from python-opcua.

kashp avatar kashp commented on August 22, 2024

thanks oroultet
I decided to restart application from supervisord on getting read or write error

But my application doesn't exit on restart the server.

Please help. I am confused how to handle this siutuation

try:

            client = Client("opc.tcp://192.168.190.129:49320")
            client.connect()
            root = client.get_root_node()
            state = root.get_child(["0:Objects", "2:Simulation.Warehouse.Scanner.PKG_W_DATA[1,1]"])
            fast = root.get_child(["Objects", "2:Simulation.Warehouse.Scanner.PKG_C_DATA[1,1]"])
            handler = SubHandler()
            count=1
            while(1):
                    f.flush()
                    dv_id = ua.DataValue(ua.Variant(randint(1,10000), ua.VariantType.UInt16))
                    dv_data = ua.DataValue(ua.Variant(randint(1,10000), ua.VariantType.UInt16))
                    try:
                            state.set_value(dv_id)
                            fast.set_value(dv_data)
                            print (state.get_value(),fast.get_value())
                    except:
                            print("unable to read")
                            exit()
                    print ("count",count)

                    count=count+1
                    time.sleep(4)
    except:
            print("error")
            exit()

from python-opcua.

oroulet avatar oroulet commented on August 22, 2024

I guess the keepalive thread is still running. call client.keepalive.stop()
then stop.
Does it work?

I do not see how to do this automatically in library.

Thanks for your help discovering all these things :-)

On Sat, 8 Aug 2015 at 09:12 kashp [email protected] wrote:

thanks oroultet
I decided to restart application from supervisord on getting read or write
error

But my application doesn't exit on restart the server.

Please help. I am confused how to handle this siutuation

try:
client = Client("opc.tcp://192.168.190.129:49320")
client.connect()
root = client.get_root_node()
state = root.get_child(["0:Objects",
"2:Simulation.Warehouse.Scanner.PKG_W_DATA[1,1]"])
fast = root.get_child(["Objects",
"2:Simulation.Warehouse.Scanner.PKG_C_DATA[1,1]"])
handler = SubHandler()

        count=1
        while(1):
                f.flush()
                dv_id = ua.DataValue(ua.Variant(randint(1,10000), ua.VariantType.UInt16))
                dv_data = ua.DataValue(ua.Variant(randint(1,10000), ua.VariantType.UInt16))
                try:
                        state.set_value(dv_id)
                        fast.set_value(dv_data)
                        print (state.get_value(),fast.get_value())
                except:
                        print("unable to read")
                        exit()
                print ("count",count)

                count=count+1
                time.sleep(4)
except:
        print("error")
        exit()


Reply to this email directly or view it on GitHub
#21 (comment)
.

from python-opcua.

kashp avatar kashp commented on August 22, 2024

Thanks for your help now i am able to exit the program, now i can restart the application in case of server failure.
:)

from python-opcua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.