Closed jrtrussell81 closed 3 years ago
Should be able to catch the exception and then raise your own exception with your own message.
Kirk
I am catching the exception, but after it catches it gives the common causes...
Connecting to TEST @ WLC IP 1.1.1.1 (this is mine)
Failed to TEST @ WLC IP 1.1.1.1 TCP connection to device failed. (this is my catch message)
Common causes of this problem are:
1. Incorrect hostname or IP address.
2. Wrong TCP port.
3. Intermediate firewall blocking access.
Device settings: cisco_wlc_ssh 1.1.1.1:22
nm_exceptions = (nm.ssh_exception.NetMikoTimeoutException, nm.ssh_exception.NetMikoAuthenticationException)
try: connect_wlc = nm.ConnectHandler(ip=current_wlc_ip, banner_timeout=10, device_type='cisco_wlc_ssh', username=username, password=password) out1 = '' for cmd in commands: out1 += connect_wlc.send_command(cmd) print(out1) except nm_exceptions as e: print('Failed to', current_wlc, '@ WLC IP ' + current_wlc_ip, e) connect_wlc.disconnect()
Should be able to catch the exception and then raise your own exception with your own message.
Kirk
I am catching the exception, but after it catches it gives the common causes...
Connecting to TEST @ WLC IP 1.1.1.1 (this is mine)
Failed to TEST @ WLC IP 1.1.1.1 TCP connection to device failed. (this is my catch message)
Common causes of this problem are:
Device settings: cisco_wlc_ssh 1.1.1.1:22
Should be able to catch the exception and then raise your own exception with your own message.
Kirk
I am catching the exception, but after it catches it gives the common causes...
Connecting to TEST @ WLC IP 1.1.1.1 (this is mine)
Failed to TEST @ WLC IP 1.1.1.1 TCP connection to device failed. (this is my catch message)
Common causes of this problem are:
Incorrect hostname or IP address.
Wrong TCP port.
Intermediate firewall blocking access.
Device settings: cisco_wlc_ssh 1.1.1.1:22
Hello. You are catching the exception as 'e', then printing your custom statement however, you include the exception 'e' at the very end of your print statement which is why it is still printing it. Remove the variable e and it should work the way you want.
Should be able to catch the exception and then raise your own exception with your own message.
Kirk
I am catching the exception, but after it catches it gives the common causes... Connecting to TEST @ WLC IP 1.1.1.1 (this is mine) Failed to TEST @ WLC IP 1.1.1.1 TCP connection to device failed. (this is my catch message) Common causes of this problem are:
- Incorrect hostname or IP address.
- Wrong TCP port.
- Intermediate firewall blocking access.
Device settings: cisco_wlc_ssh 1.1.1.1:22
Hello. You are catching the exception as 'e', then printing your custom statement however, you include the exception 'e' at the very end of your print statement which is why it is still printing it. Remove the variable e and it should work the way you want.
You are definitely correct...I was just hoping to see the actual exception whether it be timeout or authentication...unfortunately the timeout exception carries with it the "common causes" paragraph which I don't really care for...all I was wanting to see is the "TCP connection to device failed" part...o well. Thanks!
@jrtrussell81 You have the string in the variable e
(str(e)). You can parse that string and extract what you want from it.
You can also have multiple separate except statements if you want to catch the different types of exceptions.
@jrtrussell81 You have the string in the variable
e
(str(e)). You can parse that string and extract what you want from it.You can also have multiple separate except statements if you want to catch the different types of exceptions.
I am not to sure how to do that exactly...do you have example code?
Is there guidance on how to suppress the "Common Causes" output for connecthandler exceptions? I am already printing a short explanation...
So I do not want to see:
Common causes of this problem are:
Device settings: cisco_wlc_ssh 1.1.1.1:22