Is there a way to do try, except over ConnectHandler.enable()? #3186
Closed
hfakoor222
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to skip over enable when the "secret" is not provided in a list of devices, or incase the secret changes and I am not able to go into enable mode.
for example I tried this code:
exceptions = (netmiko.NetmikoAuthenticationException, netmiko.ReadException, netmiko.ReadTimeout, netmiko.NetmikoTimeoutException, netmiko.exceptions.SSHException)
ConnectHandler = netmiko.ConnectHandler(
device_type=device_type,
host=ip,
username=username,
password=password,
port=22,
secret=data["secret"] if "secret" in data else False
)
if ConnectHandler:
try:
ConnectHandler.enable()
except exceptions as e:
print("Could not connect to {}".format(ip))
When I tested this without a provided secret in my list, it returns an error. Note in the code above the ConnectHandler parses the info with or without a secret, now I just need to be able to skip over .enable() when it doesn't work.
here is the traceback:
raceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
coro = func()
File "", line 1, in
File "C:\Users*\Desktop*\Python_Scripting\OSPF_Base_Script\Connect_Handler.py", line 43, in connect_parser
ConnectHandler.enable()
File "C:\Users*\Desktop*\Python_Scripting\OSPF_Base_Script\venv\lib\site-packages\netmiko\cisco_base_connection.py", line 25, in enable
return super().enable(
File "C:\Users*\Desktop*\Python_Scripting\OSPF_Base_Script\venv\lib\site-packages\netmiko\base_connection.py", line 1934, in enable
self.write_channel(self.normalize_cmd(self.secret))
File "C:\Users*\Desktop*\Python_Scripting\OSPF_Base_Script\venv\lib\site-packages\netmiko\base_connection.py", line 1879, in normalize_cmd
command = command.rstrip()
AttributeError: 'bool' object has no attribute 'rstrip'
Beta Was this translation helpful? Give feedback.
All reactions