cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1314
Views
2
Helpful
6
Replies

Netmiko Python Error

MerakiGnome
Meraki Community All-Star
Meraki Community All-Star

Hello

Currently building a script to bulk audit a network of over 700 switches to compile an IP and VLAN schema. All going well except I’m getting the below error for 4 switches:

Connecting to <host> (x.x.x.x)...
Failed to connect to <host> (x.x.x.x):
Pattern not detected: '<host>\\#' 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.

I’ve tried the recommended step 2 and added a timeout value.

Darren OConnor
https://www.linkedin.com/in/darrenoconnor
6 Replies 6

Have you tried running the script for just those 4 switches that fail, and take a look at the output?
And is this failing during the connection setup or when you're issuing a send_command ?

Is it possible that the credentials you're using in the script aren't granted enable mode during login, or the enable password is different on these switches?
You might be able to manually verify by SSH-ing into those devices using the same credentials as the script is using.

 

 

---
Please mark helpful answers & solutions
---

MerakiGnome
Meraki Community All-Star
Meraki Community All-Star

Hey @Jonatan Jonasson 

I can confirm that the script includes an element to allow for Enable mode.  I can log into the switches individually using the credentials within the script.

Ill try just running the script against the four switches alone.

 

Ta

Darren OConnor
https://www.linkedin.com/in/darrenoconnor

balaji.bandi
Hall of Fame
Hall of Fame
All going well except I’m getting the below error for 4 switches:

Are these 4 switches the same model and IOS code as the others, or any special?

Connecting to <host> (x.x.x.x)...
Failed to connect to <host> (x.x.x.x):
Pattern not detected: '<host>\\#' in output.

It's failing because it's expecting a specific prompt but can't get it, so it fails.

If you like, you can get debug output, see what is happening, and run the script against those 4 switches.

net_connect = ConnectHandler(..., session_log='debug_log.txt')

 

BB

=====️ Preenayamo Vasudevam ️=====

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

MerakiGnome
Meraki Community All-Star
Meraki Community All-Star

Thanks for the assistance @balaji.bandi.  Do I just append the above to the end of my script?  Where will it output the log file?

Darren OConnor
https://www.linkedin.com/in/darrenoconnor

depends on how your connection handles 

example :

net_connect = ConnectHandler(
    device_type='cisco_ios',
    host='x.x.x.x',
    username='admin',
    password='password',
    session_log='debug_session.txt',      # The 'logging' module above captures information.
)

BB

=====️ Preenayamo Vasudevam ️=====

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

@MerakiGnome try setting wildcard expect_string like r'[#>]' in ur ConnectHandler to handle variations in hostname or prompt character, additionally, use session_log='debug.txt' to see if those specific switches are stuck on a login banner or a "password expired"