'Paramiko / Netmiko SSH Error - 'paramiko.buffered_pipe.PipeTimeout'

netmiko script

from netmiko import ConnectHandler

    iosv_l2 = {
        'device_type': 'cisco_ios',
        'ip': '192.168.122.2',
        'username': 'test',
        'password': '123',
    }

    net_connect = ConnectHandler(**iosv_l2)
    output = net_connect.send_command('show ip int brief')
    print (output)

    config_commands = ['int loop 0', 'ip address 1.1.1.1 255.255.255.0']
    output = net_connect.send_config_set(config_commands)
    print (output)

    for n in range (2,21):
        print ("Creating VLAN " + str(n))
        config_commands = ['vlan ' + str(n), 'name Python_VLAN ' + str(n)]
        output = net_connect.send_config_set(config_commands)
        print (output) 

I end up with this error


    Interface              IP-Address      OK? Method Status                Protocol
    GigabitEthernet0/0     unassigned      YES unset  up                    up
    GigabitEthernet0/1     unassigned      YES unset  down                  down
    Vlan1                  192.168.122.2   YES manual up                    up
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 699, in recv
        out = self.in_buffer.read(nbytes, self.timeout)
      File "/usr/local/lib/python3.8/dist-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 "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 534, in _read_channel_expect
        new_data = self.remote_conn.recv(MAX_BUFFER)
      File "/usr/local/lib/python3.8/dist-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 "ssh.py", line 15, in 
        output = net_connect.send_config_set(config_commands)
      File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1607, in send_config_set
        output = self.config_mode(*cfg_mode_args)
      File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py", line 49, in config_mode
        return super(CiscoBaseConnection, self).config_mode(
      File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1514, in config_mode
        if not self.check_config_mode():
      File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco/cisco_ios.py", line 31, in check_config_mode
        return super(CiscoIosBase, self).check_config_mode(
      File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py", line 37, in check_config_mode
        return super(CiscoBaseConnection, self).check_config_mode(
      File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1501, in check_config_mode
        output = self.read_until_pattern(pattern=pattern)
      File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 609, in read_until_pattern
        return self._read_channel_expect(*args, **kwargs)
      File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 542, in _read_channel_expect
        raise NetMikoTimeoutException(
    netmiko.ssh_exception.NetMikoTimeoutException: Timed-out reading channel, data not available.

Network Topology

How I fix this issue...



Solution 1:[1]

Did you configure the user privilege level? When configuring users, use username test privilege 15 password 123. If you forget to mention privilege rights you will end up with this error.

Solution 2:[2]

Seems that your network topology based on GNS3 project software and I pretty sure that you have CPU issue or rather, CPU hogging of your L2/L3 devices. It can be the reason of SSH timeout for your netmiko scripts.

Solution 3:[3]

I have faced with similar error in a cisco box and different vendor as well. I have fixed the problem after fixing the commands that I sent to devices. It was weird because it should give an error in reply of the output if the command run does not exist. What I have realized that if there are commands in which starts with the command you typed, it turns with an timeout error. So that it is hard to identify the problem for the first time. In your case, please make sure if you have a right to configure address under loop 0 interface. If you don't have a right, you will not be allowed to login that context so that other than giving an error in reply of output, you will face with timeout error. Because you were in wrong context, there is ip address-pool command which might cause the timeout issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 GoodTimes
Solution 3 Baris Ozensel