I’m writing a code that reads data from an OPC server. This is a summary:

url = opc.tcpXXXXX
client = Client(url)
client.connect()

And then in a while loop I want to read data from the server for several days:

While True:
Data1 =client.get_node(“ns=4;i=3”)
Data1_Val = Data1.get_value()
#write it to sql table
time.sleep(120)

I’m reading 20 nodes the same way in the same while loop.
At first, all works fine. But, after a while the script would still be running but without any data acquisition! What I mean is that after about 2 hours, I will no longer get data from the server.
What could possibly be the problem?
Thanks!
What is your opc server ?
1-) Ex. in kepserverex opc server runtime has 2 hour for a free version. then it ill stoped read data and publish to opc server. Maybe other opc servers are like this.
2-) OPC servers include some config settings like connection time or alive time or someting like that. Check your server settings.
3-) Some Opc servers need certificate, if u connect wihout certificate it ill close session after a while for security.
4-) Sometimes our request failed from server , because server cant read data of your wish. This error can lead to logging out, it can also be in the configuration settings of this server.
U should check them, if u can say your opc server name i can search
Python OPC-UA client stops reading after a while