MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / close_secure_channel

Method close_secure_channel

opcua/client/ua_client.py:214–232  ·  view source on GitHub ↗

close secure channel. It seems to trigger a shutdown of socket in most servers, so be prepare to reconnect. OPC UA specs Part 6, 7.1.4 say that Server does not send a CloseSecureChannel response and should just close socket

(self)

Source from the content-addressed store, hash-verified

212 return response.Parameters
213
214 def close_secure_channel(self):
215 """
216 close secure channel. It seems to trigger a shutdown of socket in most servers, so be prepare to reconnect.
217 OPC UA specs Part 6, 7.1.4 say that Server does not send a CloseSecureChannel response and should just close
218 socket
219 """
220 self.logger.info("close_secure_channel")
221 request = ua.CloseSecureChannelRequest()
222 try:
223 future = self._send_request(request, message_type=ua.MessageType.SecureClose)
224 with self._lock:
225 # some servers send a response here, most do not ... so we ignore
226 future.cancel()
227 except (socket.error, OSError) as exc:
228 if exc.errno in (errno.ENOTCONN, errno.EBADF):
229 # Socket is closed, so can't send CloseSecureChannelRequest.
230 self.logger.warning("close_secure_channel() failed: socket already closed")
231 else:
232 raise
233
234 def is_secure_channel_open(self):
235 return self._connection.is_open()

Callers

nothing calls this directly

Calls 1

_send_requestMethod · 0.95

Tested by

no test coverage detected