ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.61k stars 1.31k forks source link

Netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available. (F5 device) #3030

Open sindhujit1 opened 1 year ago

sindhujit1 commented 1 year ago

I am trying to get some basic info from an F5 device through netmiko and running into an error:

netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

Code:

ssh = ConnectHandler(device_type="f5_ltm",ip="x.x.x.x",username="xxx",password="xxx",
port=22,verbose=False)
ssh.disable_paging()
output = {}
ssh.send_command_timing('imish')
ssh.find_prompt()

if not ssh.check_enable_mode():
ssh.enable()

output['Change Output'] = ssh.send_config_set(['''imish show ip prefix-list DEFAULT-VIP'''])
print(output['Change Output'],"output['Change Output']")
check_save_config = ssh.save_config()

Stack trace:

Traceback (most recent call last):
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/paramiko/channel.py", line 699, in recv
    out = self.in_buffer.read(nbytes, self.timeout)
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/paramiko/buffered_pipe.py", line 164, in read
    raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/netmiko/base_connection.py", line 573, in _read_channel_expect
    new_data = self.remote_conn.recv(MAX_BUFFER)
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/paramiko/channel.py", line 701, in recv
    raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/sgang31/netadc3/arista/views/views_initial_arista.py", line 111, in getarista
    output['Change Output'] = ssh.send_config_set(['''imish show ip prefix-list DEFAULT-VIP'''])
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/netmiko/base_connection.py", line 1921, in send_config_set
    new_output = self.read_until_pattern(pattern=pattern)
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/netmiko/base_connection.py", line 655, in read_until_pattern
    return self._read_channel_expect(*args, **kwargs)
  File "/home/sgang31/.venvs3/netadc3.8/lib64/python3.8/site-packages/netmiko/base_connection.py", line 583, in _read_channel_expect
    raise NetmikoTimeoutException(
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.
sindhujit1 commented 1 year ago

The issue seems to be partly because the prompt changes in the F5 when we move to the dynamic routing module which uses imish

[root@xxx-f5:Active:Not All Devices Synced] config # imish xxxf5.lab.aexp.com[0]>enable xxxf5.lab.aexp.com[0]#

How do we catch or manage this in netmiko ? @ktbyers

joaosousa997 commented 1 year ago

I would recommend on ConnectHandler to add global_delay_factor or test with the different timeouts to see if it works.

EDIT Sorry didn't saw your last comment, you can try to change send_command_timming() to send_command() and add the expect_string=r"#", i you want to keep the timing just add read_timeout=bool