fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

Paramiko Timeout issue #73

Open WindfuryARS opened 3 years ago

WindfuryARS commented 3 years ago

I got a problem regarding "paramiko.buffered_pipe.PipeTimeout". My script could have expected output while I'm executing it on my MAC

from netmiko import ConnectHandler
from datetime import datetime
import time
import getpass

def getPTPstate(username,pw):
    cisco = {
        'device_type': 'cisco_nxos',
        'host': "10.122.164.139",
        'username': username,
        'password': pw
    }
    all_device = [cisco]

    for i in all_device:
        net_connect = ConnectHandler(**i)
        output1 = net_connect.send_command("show ptp clock | in Identity | awk  '{print $4}'").strip("\n")
        output2 = net_connect.send_command('show switchname').replace(" ","").strip()
        print(output2 + "'s PTP GM is " + output1)

getPTPstate("admin","cisco!123")

$ python3 /Users/hancai/Desktop/ptplogin.py F340.09.16-93180YC-FX-CD1_N93-1's PTP GM is 00:de:fb:ff:fe:fa:47:87

Somehow, it would return incorrect output if I was running same script in another server. I suppose there is performance issue in server, do we have any way to extend Timeout value?

$ python3 ptplogin.py Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File "/usr/local/lib/python3.7/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 "/usr/local/lib/python3.7/site-packages/netmiko/base_connection.py", line 541, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File "/usr/local/lib/python3.7/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 "ptplogin.py", line 24, in getPTPstate("admin","cisco!123") File "ptplogin.py", line 19, in getPTPstate output1 = net_connect.send_command("show ptp clock | in Identity | awk '{print $4}'").strip("\n") File "/usr/local/lib/python3.7/site-packages/netmiko/base_connection.py", line 1366, in send_command new_data = self.read_until_pattern(pattern=re.escape(cmd)) File "/usr/local/lib/python3.7/site-packages/netmiko/base_connection.py", line 618, in read_until_pattern return self._read_channel_expect(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/netmiko/base_connection.py", line 552, in _read_channel_expect "Timed-out reading channel, data not available." netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

``

``

fruch commented 1 year ago

What's netmiko ? this code is only tested with paramiko...