Python SSH

Hello Giovanni

Sorry about that, I was referring to your post where you shared how you “solved” the issue, but I understand that it has not yet been resolved. Let me try to help you out here.

Paramiko which you are using is a general SSH library and has a particular way in which it implements commands. With Cisco IOS, when you’re using the exec_command, it only allows a single command, and then exits, and requires you to login again. As stated in the following link:

You need to run the .invoke_shell() method to execute multiple commands.

When using Paramiko you will always need to work around these kinds of issues when connecting to Cisco IOS devices. And what might work for one vendor may not work for another. You may also find differences in the way IOS devices and ASA devices handle Paramiko.

It may be worth trying a different library. In particular, @ReneMolenaar recommends using Netmiko which you can find here:

Netmiko is based on Paramiko but the developer Kirk Byers has already done the work to ensure that it works well with a range of network devices, including Cisco devices.

I hope this has been helpful!

Laz

1 Like