-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeout/Timed-out exceptions #1596
Comments
This looks like a bug: for command in commands:
print('## Output of ' + command)
connection.send_config_set(commands)
print(connection.send_command(command)) What is in |
username test password cisc0 |
Okay, get rid of this:
And then just send the configuration commands all at once as a list instead of using a for-loop using send_config_set. |
So this is what I have for my script. `#!/usr/bin/env python from future import absolute_import, division, print_function import json #signal.signal(signal.SIGPIPE, signal.SIG_DFL) # IOError: Broken pipe if len(sys.argv) < 3: #netmiko_exceptions = (netmiko.ssh_exception.NetMikoTimeoutException, netmiko.ssh_exception.NetMikoAuthenticationException)username, password = tools.get_credentials() with open(sys.argv[1]) as cmd_file: with open(sys.argv[2]) as dev_file: for device in devices: If this is correct, I still get the Timeout exceptions. |
Can you fix your markdown... |
I got rid of the exceptions. #!/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()
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)
connection.send_config_set(commands)
print()
connection.disconnect()
except netmiko_exceptions as e:
print('Failed to ', device['ip'], e) |
I get these exceptions, Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): I am using this script: #!/usr/bin/env python
from __future__ import print_function, unicode_literals
from netmiko import Netmiko
from getpass import getpass
my_device = {
"host": "x.x.x.x",
"username": "user",
"password": getpass(),
"device_type": "cisco_ios",
"global_delay_factor": 4,
"blocking_timeout": 16
}
net_connect = Netmiko(**my_device)
cfg_commands = ["username test password cisc0"]
output = net_connect.send_config_set(cfg_commands)
print(output)
net_connect.disconnect() |
What does Netmiko logging show if you enable it for that last code? |
DEBUG:paramiko.transport:starting thread (client mode): 0x3512dd8 Switch> Switch> DEBUG:netmiko:write_channel: b'terminal length 0\n' Switch> Switch> Switch> Switch> Switch> DEBUG:netmiko:_read_channel_expect read_data: Switch> |
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) |
That work! Thank you for your help! I am curious about reverting back by sending no username... I tried but got the same exceptions. Do you want me to open another issue? |
I think removing a username in Cisco IOS has extra prompts (i.e. it prompts you if you want to do this). You will need to handle that in a special way. |
Understood. After looking at some examples, this is my code: #!/usr/bin/env python
from __future__ import print_function, unicode_literals
from netmiko import Netmiko
from getpass import getpass
import logging
logging.basicConfig(filename='send_no_config.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")
my_device = {
"host": "x.x.x.x",
"username": "user",
"password": getpass(),
"secret": "secret",
"device_type": "cisco_ios",
}
net_connect = Netmiko(**my_device)
net_connect.enable()
command = "no username test"
output = net_connect.send_config_set(command)
if "confirm" in output:
output += net .send_command_timing("\n")
print(output)
net_connect.disconnect()`
|
Yes, it looks like your code is not properly handling this extra prompting:
So it is failing. Here is an example of handling prompting: |
This worked for me.. thanks |
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
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:
Device is:
[
{
"device_type": "cisco_ios",
"ip": "10.1.60.19",
"secret": "secret",
"global_delay_factor": 2,
"blocking_timeout": 16
}
]
The text was updated successfully, but these errors were encountered: