netmiko error after connection established: Router prompt not found

Viewed 647

Using python3.7 and netmiko 3.4.0. I'm trying to connect to a Linux Ubuntu 18 server. I see that Netmiko can ssh login, but afterwards it fails with the error shown below. This is using 'device_type=linux'. If I use 'device_type=generic' I don't see the error, however this device type is not supported by the file_transfer, which requires 'linux'.

In summary, when the connection is established using device type 'linux' , netmiko throws the following error:

user_id@my-host-name ~ > 
DEBUG:netmiko:Clear buffer detects data in the channel
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:[find_prompt()]: prompt is user_id@my-host-name ~ >
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:write_channel: b'\n'

user_id@my-host-name ~ > 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:[find_prompt()]: prompt is user_id@my-host-name ~ >
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:Pattern is: 

user_id@my-host-name ~ > 

user_id@my-host-name ~ > 
DEBUG:netmiko:write_channel: b'exit\n'
DEBUG:paramiko.transport:EOF in transport thread
ERROR:root:Error when attempting to connect with SSH: Router prompt not found: 'user_id@my-host-name ~ >'

Why does Netmiko it fail , since it had established the SSH connection successfully? Is there a work around to avoid this failure?

2 Answers

After some further debugging, I think I found the root cause.

  • My linux prompt ends with ">"

  • In linux_ssh, the default prompts are defined as follows:

    LINUX_PROMPT_PRI = os.getenv("NETMIKO_LINUX_PROMPT_PRI", "$")

    LINUX_PROMPT_ALT = os.getenv("NETMIKO_LINUX_PROMPT_ALT", "#")

    LINUX_PROMPT_ROOT = os.getenv("NETMIKO_LINUX_PROMPT_ROOT", "#")

  • Therefore, Netmiko doesn't seem to match my prompt, and therefore it fails as shown above.

  • The workaround I found is disabling auto connect, and changing the linux prompt ConnectHandler(**parameters)

    establish_connection()

    set_base_prompt(alt_prompt_terminator='>')

Parameters contains 'auto_connect': False

Related