netmiko: Netmiko | Error: Telnet login failed:

Excuse my indentation, I have this script because my devices have different login credentials-

This script works fine, except when it gets to telnet section, it unable to login to devices, I this on multiple devices but it gives this error Error: Telnet login failed: [ipaddress]

import netmiko
from netmiko import ConnectHandler
from operator import itemgetter
from time import sleep
        try:
            net_connect = ConnectHandler(device_type='cisco_ios_ssh', ip=ip, username=username1, password=password1, secret=password1)
            connection_protocol = 'ssh'
        except:
                        try:
                                net_connect = ConnectHandler(device_type='cisco_ios_ssh', ip=ip, username=username2, password=password2, secret=password2)
                                connection_protocol = 'ssh'
                        except:

                                try:
                                        net_connect =  ConnectHandler(device_type='cisco_ios_telnet', ip=ip, username=username1, password=password1, port=23, verbose=False)
                                        connection_protocol = 'telnet'

                                except Exception as e:
                                        print "Error: " + str(e)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Thanks!! Adding global_delay_factor solved my connection failed issue with napalm.

You could try setting global_delay_factor: 2 (or 4) and see if it makes any difference. This is an argument to ConnectHandler

You would probably need to go into Pdb at about this location:

https://github.com/ktbyers/netmiko/blob/v2.4.2/netmiko/cisco_base_connection.py#L102

I am not seeing on the face of it why Netmiko is not sending the Username (except possibly your device is really slow and hence the global delay factor recommendation).

This is my code snippet:

  from napalm import get_network_driver
  from pprint import pprint
  
  driver = get_network_driver('ios')
  conn_method = {'port': 5036, 'transport': 'telnet', 'global_delay_factor': 2, 'secret': 'nornir'}
  host = '127.0.0.1'
  user = 'nornir'
  passwd = 'nornir'
  
  # With context manager
  with driver(hostname=host, username=user, password=passwd, optional_args=conn_method ) as device:
      print('Getting facts')
      pprint(device.get_facts())