Saturday, July 23, 2022

[SOLVED] How do you handle errors raised in Python Paramiko?

Issue

self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
    self.ssh.connect(self.hostname, username=self.username, password=self.password)
except SSHException:
    #do something

I was wondering how to handle errors raised by Paramiko when trying to connect to an SSH server?


Solution

Depends on your application.

Here are some possible actions:

  • Terminate
  • Retry
  • Log the error and continue doing something else


Answered By - ThiefMaster
Answer Checked By - Terry (WPSolving Volunteer)