Skip to content
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

Closed
kensaut opened this issue Mar 2, 2020 · 15 comments
Closed

Timeout/Timed-out exceptions #1596

kensaut opened this issue Mar 2, 2020 · 15 comments

Comments

@kensaut
Copy link

kensaut commented Mar 2, 2020

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:

#!/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
}
]

@ktbyers
Copy link
Owner

ktbyers commented Mar 2, 2020

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 commands list?

@kensaut
Copy link
Author

kensaut commented Mar 2, 2020

username test password cisc0
username test1 secret cisco0

@ktbyers
Copy link
Owner

ktbyers commented Mar 2, 2020

Okay, get rid of this:

print(connection.send_command(command))

And then just send the configuration commands all at once as a list instead of using a for-loop using send_config_set.

@kensaut
Copy link
Author

kensaut commented Mar 2, 2020

So this is what I have for my script.

`#!/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)
connection.send_config_set(commands)
print()
connection.disconnect()
except netmiko_exceptions as e:
print('Failed to ', device['ip'], e)`

If this is correct, I still get the Timeout exceptions.

@ktbyers
Copy link
Owner

ktbyers commented Mar 2, 2020

Can you fix your markdown...

@kensaut
Copy link
Author

kensaut commented Mar 2, 2020

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)

@kensaut
Copy link
Author

kensaut commented Mar 2, 2020

I get these exceptions,

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 "C:\Users\ksauter\Documents\Python\Scripts\03-02-2020_monday_config_changes.py", line 21, in
output = net_connect.send_config_set(cfg_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.

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()

@ktbyers
Copy link
Owner

ktbyers commented Mar 2, 2020

@kensaut
Copy link
Author

kensaut commented Mar 2, 2020

DEBUG:paramiko.transport:starting thread (client mode): 0x3512dd8
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-1.99-Cisco-1.25
INFO:paramiko.transport:Connected (version 1.99, client Cisco-1.25)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-sha1-96'] server mac:['hmac-sha1', 'hmac-sha1-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group-exchange-sha1
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha1
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:Got server p (2048 bits)
DEBUG:paramiko.transport:kex engine KexGex specified hash_algo
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for x.x.x.x: b'"key"'
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 4096 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:netmiko:read_channel:

Switch>
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:

Switch>
DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is Switch>
DEBUG:netmiko:read_channel:
DEBUG:netmiko:In disable_paging
DEBUG:netmiko:Command: terminal length 0

DEBUG:netmiko:write_channel: b'terminal length 0\n'
DEBUG:netmiko:Pattern is: terminal\ length\ 0
DEBUG:netmiko:_read_channel_expect read_data: t
DEBUG:netmiko:_read_channel_expect read_data: erminal length 0

Switch>
DEBUG:netmiko:Pattern found: terminal\ length\ 0 terminal length 0

Switch>
DEBUG:netmiko:terminal length 0

Switch>
DEBUG:netmiko:Exiting disable_paging
DEBUG:netmiko:write_channel: b'terminal width 511\n'
DEBUG:netmiko:Pattern is: terminal\ width\ 511
DEBUG:netmiko:_read_channel_expect read_data: t
DEBUG:netmiko:_read_channel_expect read_data: erminal width 511

Switch>
DEBUG:netmiko:Pattern found: terminal\ width\ 511 terminal width 511

Switch>
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is: #
DEBUG:netmiko:_read_channel_expect read_data:

DEBUG:netmiko:_read_channel_expect read_data: Switch>
DEBUG:paramiko.transport:EOF in transport thread

@ktbyers
Copy link
Owner

ktbyers commented 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)

@kensaut
Copy link
Author

kensaut commented Mar 2, 2020

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?

@ktbyers
Copy link
Owner

ktbyers commented Mar 2, 2020

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.

@kensaut
Copy link
Author

kensaut commented Mar 3, 2020

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()`
And my error:
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_send_no_config.py", line 25, in <module>
    output = net_connect.send_config_set(command)
  File "C:\Users\ksauter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\netmiko\base_connection.py", line 1735, in send_config_set
    new_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.

And the debug:
DEBUG:paramiko.transport:starting thread (client mode): 0x3482dd8
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-1.99-Cisco-1.25
INFO:paramiko.transport:Connected (version 1.99, client Cisco-1.25)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-sha1-96'] server mac:['hmac-sha1', 'hmac-sha1-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group-exchange-sha1
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha1
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:Got server p (2048 bits)
DEBUG:paramiko.transport:kex engine KexGex specified hash_algo <built-in function openssl_sha1>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for x.x.x.x: b'key'
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 4096 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:netmiko:read_channel: 

Switch>
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel: 

Switch>
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:[find_prompt()]: prompt is Switch>
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:In disable_paging
DEBUG:netmiko:Command: terminal length 0

DEBUG:netmiko:write_channel: b'terminal length 0\n'
DEBUG:netmiko:Pattern is: terminal\ length\ 0
DEBUG:netmiko:_read_channel_expect read_data: t
DEBUG:netmiko:_read_channel_expect read_data: erminal length 0

Switch>
DEBUG:netmiko:Pattern found: terminal\ length\ 0 terminal length 0

Switch>
DEBUG:netmiko:terminal length 0

Switch>
DEBUG:netmiko:Exiting disable_paging
DEBUG:netmiko:write_channel: b'terminal width 511\n'
DEBUG:netmiko:Pattern is: terminal\ width\ 511
DEBUG:netmiko:_read_channel_expect read_data: t
DEBUG:netmiko:_read_channel_expect read_data: erminal width 511

Switch>
DEBUG:netmiko:Pattern found: terminal\ width\ 511 terminal width 511

Switch>
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is: Switch
DEBUG:netmiko:_read_channel_expect read_data: 


DEBUG:netmiko:_read_channel_expect read_data: Switch>
DEBUG:netmiko:Pattern found: Switch 

Switch>
DEBUG:netmiko:write_channel: b'enable\n'
DEBUG:netmiko:Pattern is: (Switch|ssword)
DEBUG:netmiko:_read_channel_expect read_data: e
DEBUG:netmiko:_read_channel_expect read_data: nable

Password: 
DEBUG:netmiko:Pattern found: (Switch|ssword) enable

Password: 
DEBUG:netmiko:write_channel: b'secret\n'
DEBUG:netmiko:Pattern is: Switch
DEBUG:netmiko:_read_channel_expect read_data: 

Switch#
DEBUG:netmiko:Pattern found: Switch 

Switch#
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is: Switch
DEBUG:netmiko:_read_channel_expect read_data: 


DEBUG:netmiko:_read_channel_expect read_data: Switch#
DEBUG:netmiko:Pattern found: Switch 

Switch#
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is: #
DEBUG:netmiko:_read_channel_expect read_data: 


DEBUG:netmiko:_read_channel_expect read_data: Switch#
DEBUG:netmiko:Pattern found: # 

Switch#
DEBUG:netmiko:write_channel: b'config term\n'
DEBUG:netmiko:Pattern is: config\ term
DEBUG:netmiko:_read_channel_expect read_data: c
DEBUG:netmiko:_read_channel_expect read_data: onfig term

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#
DEBUG:netmiko:Pattern found: config\ term config term

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is: #
DEBUG:netmiko:_read_channel_expect read_data: 


DEBUG:netmiko:_read_channel_expect read_data: Switch(config)#
DEBUG:netmiko:Pattern found: # 

Switch(config)#
DEBUG:netmiko:write_channel: b'no username test\n'
DEBUG:netmiko:Pattern is: no\ username\ test
DEBUG:netmiko:_read_channel_expect read_data: n
DEBUG:netmiko:_read_channel_expect read_data: o username test

This operation will remove all username related configurations with same name.Do you want to continue? [confirm]
DEBUG:netmiko:Pattern found: no\ username\ test no username test

This operation will remove all username related configurations with same name.Do you want to continue? [confirm]
DEBUG:netmiko:Pattern is: (?:Switch|#)
DEBUG:paramiko.transport:EOF in transport thread

@ktbyers
Copy link
Owner

ktbyers commented Mar 6, 2020

Yes, it looks like your code is not properly handling this extra prompting:

DEBUG:netmiko:_read_channel_expect read_data: o username test

This operation will remove all username related configurations with same name.Do you want to continue? [confirm]
DEBUG:netmiko:Pattern found: no\ username\ test no username test

This operation will remove all username related configurations with same name.Do you want to continue? [confirm]
DEBUG:netmiko:Pattern is: (?:Switch|#)

So it is failing.

Here is an example of handling prompting:

https://github.com/ktbyers/netmiko/blob/develop/examples/use_cases/case5_prompting/send_command_prompting.py

@shubhamnetmiko
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants