Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result returns the previous command (incorrect data) #2188

Open
emil45 opened this issue Feb 20, 2023 · 0 comments
Open

Result returns the previous command (incorrect data) #2188

emil45 opened this issue Feb 20, 2023 · 0 comments
Labels

Comments

@emil45
Copy link

emil45 commented Feb 20, 2023

Hello,
Running on production with paramiko (latest) for more than a year,
Recently the output returns somewhat messy, sometimes not full,
and, most of the time gets the output of the previous command.

I am not sure why,
will try to paste here the critical parts of the code (ifs, exceptions, etc. - removed for convince):

ssh_client = paramiko.SSHClient()
ssh_client.connect(..., 
                   allow_agent=False, 
                   look_for_keys=False, 
                   banner_timeout=60)
channel = ssh_client.invoke_shell(height=self._shell_height)

def send_command(cmd, patterns):
    while channel.recv_ready():
        channel.recv(1024)
        
    channel.sendall("%s\n" % cmd)
    
    buffer = ""
    
    while True:
        <timeout code here>
        
        data_read = channel.recv(1024)
        buffer += decode(data_read)
        for pattern in patterns:
            if re.search(pattern, buffer):
                return buffer

Is there a need for sleep somewhere in the code?

@bskinn bskinn added the Support label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants