03-20-2026 02:59 PM
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.
03-20-2026 04:04 PM
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.
03-20-2026 04:27 PM
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
03-21-2026 01:51 AM
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')
=====️ Preenayamo Vasudevam ️=====
***** Rate All Helpful Responses *****
03-21-2026 06:46 AM
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?
03-21-2026 07:49 AM
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.
)
=====️ Preenayamo Vasudevam ️=====
***** Rate All Helpful Responses *****
03-21-2026 08:47 AM
@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"
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide