Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Paramiko正在删除数据的结尾_Python_Paramiko - Fatal编程技术网

Python Paramiko正在删除数据的结尾

Python Paramiko正在删除数据的结尾,python,paramiko,Python,Paramiko,我是帕拉米科的新手,我正在使用下面的代码。它返回我大部分时间都在寻找的数据,但有时它会删除我需要的数据的结尾。我确信这是一个愚蠢的错误,但我无法在文档中找到它 import paramiko nbytes = 4096 hostname = xxx port = xx username = xxxxx password = xxxxx command "Something I can't post on here, but I have verified it works" client

我是帕拉米科的新手,我正在使用下面的代码。它返回我大部分时间都在寻找的数据,但有时它会删除我需要的数据的结尾。我确信这是一个愚蠢的错误,但我无法在文档中找到它

import paramiko


nbytes = 4096
hostname = xxx
port = xx
username = xxxxx
password = xxxxx

command "Something I can't post on here, but I have verified it works"

client = paramiko.Transport((hostname, port))
client.connect(username=username, password=password)


stderr_data = []
session = client.open_channel(kind='session')
session.exec_command(command)

while True:
    if session.recv_ready():
        stderr_data.append(session.recv(nbytes))
    if session.recv_stderr_ready():
        stderr_data.append(session.recv_stderr(nbytes))
    if session.exit_status_ready():
        break

我通常设置
SSHClient
,而不是直接设置传输
SSHClient
根据需要设置传输和频道。我不知道这是否是您的问题,但这样设置您自己的频道似乎很奇怪。如果没有任何标准长度的数据,则块读取不是一个好主意。请尝试:
while session.recv_ready():stderr_data.append(session.recv(nbytes))
谢谢大家。将recv添加到while循环中而不是块读取似乎可以做到这一点。我通常设置
SSHClient
,而不是直接设置传输
SSHClient
根据需要设置传输和频道。我不知道这是否是您的问题,但这样设置您自己的频道似乎很奇怪。如果没有任何标准长度的数据,则块读取不是一个好主意。请尝试:
while session.recv_ready():stderr_data.append(session.recv(nbytes))
谢谢大家。将recv添加到while循环中而不是块读取似乎可以达到目的。