[Python] Netmiko Pattern Not Detected

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    I ran this code with cisco 2960X switch.

    from netmiko import ConnectHandler

    network_device= {
    "host": "192.168.xxx.xxx",
    "username": "xxxx",
    "password": "xxxx",
    "device_type": "cisco_ios",
    "session_log": "netmiko_session.log"
    }

    connect= ConnectHandler(**network_device)
    connect.enable()

    interface_name= "GigabitEthernet1/0/10"

    def send_command(command):
    return connect.send_command(command)
    try:
    send_command('enable')
    send_command('configure terminal')
    except Exception as e:
    print(e)
    print("Failed!")


    But after I got below error.

    Pattern not detected: 'Switch\\#' in output.

    Things you might try to fix this:
    1. Explicitly set your pattern using the expect_string argument.
    2. Increase the read_timeout to a larger value.
    You can also look at the Netmiko session_log or debug log for more information.

    Failed!


    Please check below to netmiko_session.log

    Switch#
    Switch#terminal width 511
    Switch#terminal length 0
    Switch#
    Switch#enable
    Switch#
    Switch#configure terminal
    Enter configuration commands, one per line. End with CNTL/Z.
    Switch(config)#


    I renamed switch hostname. But also same error going.

    Continue reading...

Compartilhe esta Página