Reputation: 1145
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?
Upvotes: 1
Views: 2522
Reputation: 1145
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
Upvotes: 1
Reputation: 383
Netmiko works by screen scraping. Meaning it knows it has finished executing the command if the prompt is returned. If you change the prompt, Netmiko will not know if your command finished, and will probably timeout.
DEBUG:netmiko:write_channel: b'exit\n'
Probably changes the prompt. If you use send_command
you can add the expect_string
parameter:
https://ktbyers.github.io/netmiko/docs/netmiko/index.html#netmiko.BaseConnection.send_command
Upvotes: 0