5

I have just simple script like that to connect via SSH on Nokia router and execute command "show time":

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('adres ip', port=22, username='username', password='password')
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('show time')
output = stdout.readlines()
print '\n'.join(output)
ssh.close()

Login to the node is successful. I see myself on the router, but executing command are not gonna work. I get error like that:

Traceback (most recent call last):   File "C:\Users\pkudalsk\Desktop\pyt.py", line 6, in <module>
    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('show time')   File "C:\Users\pkudalsk\Desktop\paramiko\client.py", line 479, in exec_command

    chan.exec_command(command)   File "C:\Users\pkudalsk\Desktop\paramiko\channel.py", line 63, in _check
    return func(self, *args, **kwds)   File "C:\Users\pkudalsk\Desktop\paramiko\channel.py", line 241, in exec_comman d
    self._wait_for_event()   File "C:\Users\pkudalsk\Desktop\paramiko\channel.py", line 1198, in
_wait_for_ event
    raise e EOFError

Does anyone know what can cause this problem? I tried on python 3.6 and 2.7. The same result.

Thanks

1 Answers1

0

There are 2 solution:

1.- Put this comand print('\n'.join(output)) 2.- If your problem persist, no use paramiko, use netmiko. I had the same issue with nokia routers, and I changed to netmiko. Here one example

from netmiko import ConnectHandler

device = {
    'device_type': 'nokia_sros',
    #'device_type': 'alcatel_sros',
    'ip': 'ip_add',
    'username': 'user',
    'password': 'password',
    'port': 22,
    'verbose': True
}

with ConnectHandler(**device) as net_connect:
    output = net_connect.send_command('show chassis detail')
    print(output)```
   
Blue Robin
  • 847
  • 2
  • 11
  • 31