net_connect.find_prompt() doesn't print the prompt, gives weird error in netmiko

24 views Asked by At

I'm trying to print the switch prompt and then execute the comments in netmiko using the redispatch function.

netmiko gives a weird error in the output :

Portion of the code :

try:
    
    net_connect = Netmiko(**linux_jump_16)
    net_connect.global_delay_factor = 2
    print(net_connect.find_prompt())
    print(f"\n{'*'*10}Connected to the Jump host{'*'*10}")
    print(f"\n{'~'*50}\n2. Connecting to the Dest Router\n{'~'*50}")
    print(net_connect.find_prompt(), end='')
    net_connect.write_channel(f'ssh {username}@{coreswitchNCRS1}\n')
    time.sleep(3)
    output = net_connect.read_channel()
    #print(output)

    if 'Password' in output:
        net_connect.write_channel("yes" + '\n')
        print("     Received Password Prompt, Entering password    ")
        net_connect.write_channel(password + '\n')
        time.sleep(2)

        print(f"\n{'~'*50}\nDestination Device Prompt\n{'~'*50}\n")
        #print(net_connect.find_prompt())
        cmds = ['show ip int brief', 'show ip route', 'show users']
        
        redispatch(net_connect, **NetworkDevice)
        for cmd in cmds:
            print(f"\n{'~'*50}\nIn {net_connect.find_prompt()} Executing the Command: {cmd}\n{'~'*50}")
            #router_output = net_connect.send_command(cmd, expect_string=r'>|#|$', read_timeout=10)
            router_output = net_connect.send_command(cmd, read_timeout=20)
            print(router_output)

Error Screenshot

0

There are 0 answers