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 SSH Timeout

See original GitHub issue

I am having issues SSH to a Cisco IOS device. I have tested manual SSH directly from box that I am running the script from with NO issues.

Thanks for any assistance.

#!/usr/bin/env python

from netmiko import ConnectHandler

with open('commands_file') as f:
    commands_list = f.read().splitlines()

with open('devices_file') as f:
    devices_list = f.read().splitlines()

for devices in devices_list:
    print 'Connecting to device" ' + devices
    ip_address_of_device = devices_list
    ios_device = {
        'device_type': 'cisco_ios',
        'ip': 'ip_address_of_device',
        'username': '',
        'password': '',
        'secret': ''
    }

    net_connect = ConnectHandler(**ios_device)
    output = net_connect.send_config_set(commands_list)
    print output

    net_connect = ConnectHandler(**ios_device)
    output = net_connect.send_command_expect('test aaa group tacacs+ readonly Temp1234 legacy')
    print output

Connecting to device" 10.128.96.37
Traceback (most recent call last):
  File "westfieldisescript.py", line 23, in <module>
    net_connect = ConnectHandler(**ios_device)
  File "/usr/local/lib/python2.7/dist-packages/netmiko/ssh_dispatcher.py", line 131, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 150, in __init__
    self.establish_connection()
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 506, in establish_connection
    raise NetMikoTimeoutException(msg)
netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios ip_address_of_device:22

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dBitechcommented, May 6, 2019

I don’t think the way you are creating your array of devices works the way you intend…

import time
devices = '''
          192.168.1.100
          192.168.1.86
          192.168.17.1
          '''.strip().splitlines()

print(devices)
for device in devices:
        print('~'*79)
        print('Connection to Device -',device,'-')
        time.sleep(1)

results in output that looks like the following…

['192.168.1.100', '          192.168.1.86', '          192.168.17.1']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection to Device - 192.168.1.100 -
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection to Device -           192.168.1.86 -
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection to Device -           192.168.17.1 -

notice the leading spaces on all but the first “host”, that is why you are getting the underlying socket.gaierror: [Errno 11001] getaddrinfo failed error, and subsequent netmiko.ssh_exception.NetMikoTimeoutException: Connection to device

0reactions
kshathesrhcommented, May 7, 2019

Json Error While Loading file… Hi I am getting below error when loading file using Json

Traceback (most recent call last): File “C:\MOBILY\004_Personal\Amazon-Interview\SCRIPT\List-IP-jsonload.py”, line 11, in <module> devices = json.load(dev_file) File “C:\ProgramData\Anaconda3\lib\json_init_.py”, line 296, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File “C:\ProgramData\Anaconda3\lib\json_init_.py”, line 348, in loads return _default_decoder.decode(s) File “C:\ProgramData\Anaconda3\lib\json\decoder.py”, line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File “C:\ProgramData\Anaconda3\lib\json\decoder.py”, line 353, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 4 (char 3)

Can you please advise me what went wrong …

On Tue, May 7, 2019 at 9:32 PM kirupairajah shatheeskumar < kshatheesh@gmail.com> wrote:

HI dBitch,

thanks for pointing our the error. I have fixed it. The issue was few unnecessary wide spaced before the array. The below code work fine.

Again Thanks a lot. It was a syntax error.

devices = ‘’’ 10.153.4.56 10.153.4.57 10.153.4.50 10.153.4.51 10.153.4.52 ‘’'.strip().splitlines()

#devices = [‘10.153.4.56’, ‘10.153.4.57’, ‘10.153.4.50’, ‘10.153.4.51’, ‘10.153.4.52’] for device in devices: #try: print(‘~’*79) print(‘Connection to Device’, device)

(base) C:\Users\kirups>python C:\MOBILY\004_Personal\Amazon-Interview\SCRIPT\List-IP-test.py

Connection to Device 10.153.4.56

Connection to Device 10.153.4.57

Connection to Device 10.153.4.50

Connection to Device 10.153.4.51

Connection to Device 10.153.4.52

(base) C:\Users\kirups>

Note: All devices are successfully logged in

On Tue, May 7, 2019 at 1:58 AM dBitech <notifications@github.com> wrote:

> I don't think the way you are creating your array of devices works the
> way you intend..
>
>           192.168.1.100
>           192.168.1.86
>           192.168.17.1
>           '''.strip().splitlines()
>
> print(devices)
> for device in devices:
>         print('~'*79)
>         print('Connection to Device -',device,'-')
>         time.sleep(1)
>
> results in output that looks like the following...
>
> ['192.168.1.100', '          192.168.1.86', '          192.168.17.1']
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Connection to Device - 192.168.1.100 -
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Connection to Device -           192.168.1.86 -
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Connection to Device -           192.168.17.1 -
>
> notice the leading spaces on all but the first "host", that is why you
> are getting the underlying socket.gaierror: [Errno 11001] getaddrinfo
> failed error, and subsequent netmiko.ssh_exception.NetMikoTimeoutException:
> Connection to device
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/ktbyers/netmiko/issues/575#issuecomment-489817308>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AL72CC2XKK7DDOAY67TNBATPUCZ2VANCNFSM4D3AGFVA>
> .
>


--
Kind Regards,

K.Satheeskumar

– Kind Regards,

K.Satheeskumar

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netmiko4 timeout specification · Issue #2282 · ktbyers/netmiko
SSH Banner Timeout (default: 15 seconds). ... banner_timeout: int = 15,. Time allowed for SSH banner to be present. Not implemented for telnet/ ......
Read more >
Netmiko4 read_timeout - Python for Network Engineers
In Netmiko 3.4.0 'send_command()' will search through the device's output looking for the router prompt or pattern for ten seconds. This assumes ...
Read more >
netmiko API documentation - GitHub Pages
CiscoBaseConnection is netmiko SSH class for Cisco and Cisco-like platforms. ... :param banner_timeout: Set a timeout to wait for the SSH banner (pass...
Read more >
How to use the netmiko.ssh_exception ... - Snyk
To help you get started, we've selected a few netmiko.ssh_exception.NetMikoTimeoutException examples, based on popular ways it is used in public projects.
Read more >
Netmiko Timeout Error for Python / Automating Devices
As stated by Kirk, Netmiko is a Multi-vendor library to simplify Paramiko SSH connections to network devices .
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