-
Notifications
You must be signed in to change notification settings - Fork 78
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
channel.recv() problem #38
Comments
Same issue here! |
can you guy share an example ? |
timeout = 30
display = False
cmd = passwd
password = mynewpassword
exp_dict = {
"New password: ":"{}".format(password),
"Retype new password: ":"{}".format(password),
"passwd: all authentication tokens updated successfully.":"\n"
}
prompts = []
try:
for prompt in exp_dict:
prompts.append(prompt)
except Exception:
print('Error building prompts list from exp_dict!')
return '!! Failed !!'
try:
# Create a new SSH client object
client = paramiko.SSHClient()
# Set SSH key parameters to auto accept unknown hosts
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the host
client.connect(hostname=server, username=myusername, password=mypassword)
# Create a client interaction class which will interact with the host
with SSHClientInteraction(client, timeout=timeout, display=display) as interact:
interact.send(cmd)
for prompt in prompts:
interact.expect(prompts) #expect a prompt for our prompts list
interact.send(exp_dict[interact.last_match]) #send the value assinged to prompt key
interact.send('exit')
interact.expect()
status = 'Success'
except Exception:
status = '!! Failed !!'
pass
finally:
try:
client.close()
except:
pass
return status I am experiencing this same problem. Sometimes it returns success, sometimes it returns failure. If I add a 'time.sleep(.2)' after .send(), it seems to return success more often but still not 100%. |
Same issue here!,the not set time.sleep(2),after send,the expect get erro output, especically same time the output out of order after loop send command and expect |
I am also having the same issue .. |
Facing similar issue. In my case, first partial output coming in |
Any workarounds or fix yet? |
Hi,
I've experienced issue when trying to match against output when running .expect() right after .send(). Expect does not show output as with pexpect library. It return the command I've sent along with prompts instead of returning result of the command.
If I introduce certain delay after each .send() it tends to work more correctly.
Thanks, Dragan
The text was updated successfully, but these errors were encountered: