0

I mean this if statement. Can I check what exception the e is? Is it like with checking string or trying to check it with paramiko/socket exceptions?

try:
    ssh.connect(hosts[index], ports[index], login, ssh_key, timeout=3)
    print(f'connected = {connected}')
    return True
except Exception as e:
    if e == paramiko.AuthenticationException:
        print(f'[SSH] connected = {connected}. \nerror = {str(e)}')
        print('[SSH] bad auth')
        ssh_config.check_ssh(1)
        return False
return False
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Tobiias
  • 1
  • 2
  • Welcome to Stack Overflow. The short answer is that, rather than trying to catch a general exception type and then figure out what you have, you should use a separate `except:` block for each exception type. The long answer is given by the linked duplicate. The even longer(?) answer is that [you should learn how to do some research before asking](https://meta.stackoverflow.com/questions/261592), and consider [looking for](https://duckduckgo.com/?q=python+exception+tutorial) and following [tutorials for general topics](https://docs.python.org/3/library/exceptions.html). – Karl Knechtel Dec 08 '21 at 20:50
  • It's also useful to learn how to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), and restrict your question and tags to what's relevant to the actual problem. Here, for example, you could easily run into the same problem without using `paramiko` or any other library; therefore, you don't actually have a question about that library. – Karl Knechtel Dec 08 '21 at 20:54
  • thanks for answering so quick Karl Knechtel. I sure know I can do that but I have no idea how. Could You tell me where I can find more info about different exceptions? Oh sorry i didnt see your links sent there. Anyways thanks for help! – Tobiias Dec 08 '21 at 20:56
  • Yeah sorry for bothering You without research. I have found it and my problem's solved. Thank You so much Karl! – Tobiias Dec 08 '21 at 21:16

0 Answers0