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.

Timeout/Timed-out exceptions

See original GitHub issue

I am trying to run config commands to a Cisco switch and keep getting the below error. The script, tools, etc is modified by me using Greg Mueller. Is there something that I am missing?

Traceback (most recent call last): File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\channel.py”, line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\buffered_pipe.py”, line 164, in read raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py”, line 541, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\channel.py”, line 701, in recv raise socket.timeout() socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “03-02-2020_monday.py”, line 39, in <module> connection.send_config_set(commands) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py”, line 1704, in send_config_set output = self.config_mode(*cfg_mode_args) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\cisco_base_connection.py”, line 40, in config_mode return super().config_mode(config_command=config_command, pattern=pattern) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py”, line 1595, in config_mode if not self.check_config_mode(): File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\cisco\cisco_ios.py”, line 29, in check_config_mode return super().check_config_mode(check_string=check_string, pattern=pattern) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\cisco_base_connection.py”, line 30, in check_config_mode return super().check_config_mode(check_string=check_string, pattern=pattern) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py”, line 1582, in check_config_mode output = self.read_until_pattern(pattern=pattern) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py”, line 618, in read_until_pattern return self._read_channel_expect(*args, **kwargs) File “C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py”, line 551, in _read_channel_expect raise NetmikoTimeoutException( netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

My script is below:

#!/usr/bin/env python

from __future__ import absolute_import, division, print_function

import json
import netmiko
import tools
import signal
import sys

#signal.signal(signal.SIGPIPE, signal.SIG_DFL)  # IOError: Broken pipe
signal.signal(signal.SIGINT, signal.SIG_DFL)  # KeyboardInterrupt: Ctrl-C


if len(sys.argv) < 3:
    print('Usage: cmdrunner.py commands.txt devices.json')
    exit()

#netmiko_exceptions = (netmiko.ssh_exception.NetMikoTimeoutException,
#                      netmiko.ssh_exception.NetMikoAuthenticationException)

username, password = tools.get_credentials()

with open(sys.argv[1]) as cmd_file:
    commands = cmd_file.readlines()

with open(sys.argv[2]) as dev_file:
     devices = json.load(dev_file)

for device in devices:
    device['username'] = username
    device['password'] = password
    try:
        print('-' * 79)
        print('Connecting to device:', device['ip'])
        connection = netmiko.ConnectHandler(**device)
        for command in commands:
            print('## Output of ' + command)
            connection.send_config_set(commands)
            print(connection.send_command(command))
            print()
        connection.disconnect()
    except netmiko_exceptions as e:
        print('Failed to ', device['ip'], e)`

tools are:
`from __future__ import absolute_import, division, print_function

from getpass import getpass

def get_input(prompt=''):
    try:
        line = raw_input(prompt)
    except NameError:
        line = input(prompt)
    return line


def get_credentials():
    """Prompt for and return a username and password."""
    username = get_input('Enter Username: ')
    password = None
    while not password:
        password = getpass()
        password_verify = getpass('Retype your password: ')
        if password != password_verify:
            print('Passwords do not match.  Try again.')
            password = None
    return username, password`

Device is: [ { “device_type”: “cisco_ios”, “ip”: “10.1.60.19”, “secret”: “secret”, “global_delay_factor”: 2, “blocking_timeout”: 16 } ]

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ktbyerscommented, Mar 2, 2020

You need to call .enable(). You also need to pass in a “secret” argument in “my_device”.

net_connect = Netmiko(**my_device)
net_connect.enable()
cfg_commands = ["username test password cisc0"]

output = net_connect.send_config_set(cfg_commands)
print(output)
0reactions
shubhamnetmikocommented, Jun 23, 2020

You need to call .enable(). You also need to pass in a “secret” argument in “my_device”.

net_connect = Netmiko(**my_device)
net_connect.enable()
cfg_commands = ["username test password cisc0"]

output = net_connect.send_config_set(cfg_commands)
print(output)

This worked for me… thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

TimeoutException (Java Platform SE 8 ) - Oracle Help Center
Exception thrown when a blocking operation times out. Blocking operations for which a timeout is specified need a means to indicate that the...
Read more >
Timeout exception - IBM
The most common cause is that the connection string information is invalid. The network might be blocking communication, resulting in a timeout. While...
Read more >
Simple handling of network timeouts | InfoWorld
Exception handling is an excellent way of dealing with error conditions, and allows us to separate our normal code from our error-handling code....
Read more >
Connection Timeout vs. Read Timeout for Java Sockets
In this tutorial, we'll focus on the timeout exceptions of Java socket programming. Our goal is to understand why these exceptions occur, ...
Read more >
TimeoutException Class (System) - Microsoft Learn
The exception that is thrown when the time allotted for a process or operation has expired.
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