ktbyers / netmiko

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

loop_delay Indicates that the return packet is incomplete #3398

Closed Mr-Jayden closed 8 months ago

Mr-Jayden commented 8 months ago

Hi, I sent the ‘display dev man’ command through the send_command method, but only half of the message was returned. When I increase the value of loop_delay in line 1709 of 'base_connection.py', the problem is fixed. Is there any other way I can get a full return?

Netmiko version

netmiko==4.3.0 device_type=h3c-s5560-56c-hi login param: auth = { 'device_type': 'hp_comware', 'host': "", 'username': "", 'password': "", 'port': 22, 'session_log': 'session.log' }

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

Slot 1 CPU 0:
DEVICE_NAME          : S5560-56C-HI
DEVICE_SERIAL_NUMBER : 210235A1PNH2150C000H
MAC_ADDRESS          : 083A-38F5-3130
MANUFACTURING_DATE   : 2021-05-18
VENDOR_NAME          : H3C
Fan 1:
The operation is not supported on the specified fan.
Fan 2:
The operation is not supported on the specified fan.
Power 1:
DEVICE_NAME          : LSVM1AC300
DEVICE_SERIAL_NUMBER : 210231A1SUH2140C003T
MANUFACTURING_DATE   : 2021-05-04
VENDOR_NAME          : H3C
Power 2:

"Power 2:" followed by some content but not returned

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue) (Paste the code between the quotes below)

auth = {
        'device_type': 'hp_comware',
        'host': "",
        'username': "",
        'password': "",
        'port': 22,
        'session_log': 'session.log'
    }
conn = ConnectHandler(**auth, timeout=200)
conn.send_command("display dev man")
ktbyers commented 8 months ago

@Mr-Jayden Do you get an exception stack trace when this command doesn't work?

conn.send_command("display dev man")
Mr-Jayden commented 8 months ago

I open the session.log, not any exception. When I don't make any changes, the output I get is the host name. I use send_command_timings to get the full output, but the first output contains "screen-length disable" + "hostname" + "correct output". I think the command "screen-length disable" was executed when the connection was established. I don't know why it appears in the command I executed.

Mr-Jayden commented 8 months ago

first_output

Mr-Jayden commented 8 months ago

Of course, this abnormal output does not affect my use, I just need to remove the content before "display version" on the line. I just want to know why? thank you.

ktbyers commented 8 months ago

I would probably try:

conn.send_command("display dev man", expect_string=r"\]")

Either that or put in a time.sleep(2) before you do your send_command to clear out data that hasn't been read.

time.sleep(2)
conn.clear_buffer()

conn.send_command("display dev man", expect_string=r"\]")

It looks like Netmiko is getting ahead of the device (i.e. Netmiko is ahead of where the device is just after login and this is causing some problems).

Mr-Jayden commented 8 months ago

I solved my problem through the method you gave me, thank you very much.