Netmiko should strip whitespace from host and IP fields
See original GitHub issueHi,
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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
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).
Created #1239 as a fix/placeholder for this. Closing