question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Netmiko should strip whitespace from host and IP fields

See original GitHub issue

Hi,

I am fairly new in programming and I am getting an error on my script. My list of ips are 10.xx.xx.149 and 10.xx.xx.150 saved on file name “devices”, but when i just have 1 ip on the “devices” file like 10.xx.xx.149, it will connect and run the script successfully. Having more than 1 ip on the “devices” the script is getting error. I can both ssh to both devices. Appreciate the help on this.

=================================

import netmiko
from netmiko import ConnectHandler
import getpass
from getpass import getpass

ip_list = open('devices')
for IP in ip_list:
    SW = {
    'device_type': 'cisco_ios', 
    'ip':    IP,
    'username': 'admin',
    'password': 'admin',
    }
    
    print('Connecting to the device ' + IP)
    net_connect = ConnectHandler(**SW)

    output = net_connect.send_config_from_file(config_file='config')
    print(output)
    output = net_connect.send_command('show ip int brief')
    print(output)

================================ ERROR below

Connecting to the device 10.xx.xx.149

Traceback (most recent call last): File “C:\Users\rome\Anaconda3\lib\site-packages\netmiko-2.3.3-py3.7.egg\netmiko\base_connection.py”, line 860, in establish_connection File “C:\Users\rome\Anaconda3\lib\site-packages\paramiko\client.py”, line 334, in connect to_try = list(self._families_and_addresses(hostname, port)) File “C:\Users\rome\Anaconda3\lib\site-packages\paramiko\client.py”, line 204, in _families_and_addresses hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM File “C:\Users\rome\Anaconda3\lib\socket.py”, line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “test11.py”, line 16, in <module> net_connect = ConnectHandler(**SW) File “C:\Users\rome\Anaconda3\lib\site-packages\netmiko-2.3.3-py3.7.egg\netmiko\ssh_dispatcher.py”, line 238, in ConnectHandler File “C:\Users\rome\Anaconda3\lib\site-packages\netmiko-2.3.3-py3.7.egg\netmiko\base_connection.py”, line 314, in init File “C:\Users\rome\Anaconda3\lib\site-packages\netmiko-2.3.3-py3.7.egg\netmiko\base_connection.py”, line 866, in establish_connection netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios 10.xx.xx.149 :22

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Jun 12, 2019

I am going to mark this as an issue to be fixed as I have seen this problem happen a few times and we should just have Netmiko handle it (i.e. strip leading and trailing whitespace on the host and IP fields).

0reactions
carlmontanaricommented, Jun 12, 2019

Created #1239 as a fix/placeholder for this. Closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to do ssh on multiple cisco devices using netmiko in python
I am trying run this below script for multiple devices and it is working only for last device according to below script. Please...
Read more >
Automate Simple Networking Tasks with Python - LinkedIn
By creating a few very simple Python scripts you could be on your way ... measure add .strip() to omit and heading or...
Read more >
netmiko API documentation - GitHub Pages
The ssh_autodetect module is used to auto-detect the netmiko device_type to use to further initiate a new SSH connection with a remote host....
Read more >
automation | The NTC Mag - NTC Blog
Libraries such as netmiko, NAPALM, and Scrapli greatly ease the process of connecting to, and configuring, a network device. This blog will examine...
Read more >
NAPALM Documentation - Read the Docs
Cisco IOS will also reject replace operations that are missing a certificate (when the current configuration has a self-signed certificate).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found