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.

ValueError:Failed to exit configuration mode

See original GitHub issue

HI dear ktbyers: I have an issue about the netmiko, my code is:

from netmiko import ConnectHandler
import netmiko
import getpass
import socket


username = input('Enter your SSH/Telnet username: ')
password_now = getpass.getpass('Enter your SSH/Telnet password now: ') 
password = getpass.getpass('Enter your new password: ')

cisco_3560_18 = {
                    'device_type':'cisco_ios',
                    'ip':'XXXXXXX',
                    'username':username,
                    'password':password_now
                    }

cisco_3560_19 = {
                    'device_type':'cisco_ios',
                    'ip':'1XXXXXXX9',
                    'username':username,
                    'password':password_now
                    }
devices_cisco = [cisco_3560_18,cisco_3560_19]
for device in devices_cisco:
    try:
        connect = ConnectHandler(**device)
        print('Successfully connected to ' + device['ip'])
        
        config_commands ='username admin secret 12345'
        #connect.send_command('conf t')
        output = connect.send_config_set(config_commands)
        print(output)
    except netmiko.ssh_exception.NetMikoTimeoutException:
        print(device['ip' + 'is not reachable.'])
    except netmiko.ssh_exception.NetmikoAuthenticationException:
        print('username or password incorrect')

and there is an error is :ValueError:Failed to exit configuration mode (output = connect.send_config_set(config_commands))

and i follow your reply for other issue add the ‘exit_config_mode=False’ and ‘delay_factor=4’ there will be another error: username admin secret 12345 ^ %invalid input detected at ‘^’ marker. XXXXX#

this two swtiches is cisco WS-C3560-24TS, and ios is :C3560-IPSERVICESK9-M

and i use netmiko.send_command to show information can works.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Mic0623commented, Jan 6, 2021

Adding the parenthesis breaks how Netmiko checks for whether we are in config-mode or not:

https://github.com/ktbyers/netmiko/blob/netmiko4_exp/netmiko/cisco/cisco_ios.py#L26

You can see this argument:

check_string=")#"

So trailing parenthesis and a pound sign is the indicator we are using for determining configuration mode.

Unfortunately, in this case you would have to change the hostname to get Netmiko to work properly…

Regards, Kirk

Thank you!Kirk,when i change the hostname of the device, the problem is solved. Thank you very much!

0reactions
ktbyerscommented, Jan 6, 2021

@Mic0623 Yeah, sorry you ran into this…unfortunately, certain string patterns for determining device state (config mode, enable mode, et cetera) are necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to enter configuration mode in Netmiko while trying ...
I'm new to Python and Netmiko. I;m trying to use netmiko to login to aruba switches. while i pass on some commands using...
Read more >
netmiko.juniper.juniper API documentation
Commit the entered configuration. Raise an error and return the failure if the commit fails. Automatically enters configuration mode.
Read more >
How to use the netmiko.log function in netmiko
... config mode if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") log.debug(f"exit_config_mode: {output}") return output.
Read more >
Python ConnectHandler.enable Examples, netmiko. ...
def main(): ''' Connects to router and switches to config mode ... "ipv6" #else: # raise ValueError("BGP neighbor parsing failed") """ 'show ip...
Read more >
4. Configuring in the MD-CLI
Navigation outside the configure branch is allowed and does not exit the configuration mode. (ex)[configure router "Base"]. A:admin@node-2# /show uptime. System ...
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