question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Paramiko-expect Timeout Issue

See original GitHub issue

Hi Team,

I’m using paramiko expect for automating one of my terminal session, however I’m facing an issue with the prompt, please find below the error

>>> import paramiko
>>> import re
>>> from paramiko_expect import SSHClientInteraction
>>> 
>>> client = paramiko.SSHClient()
>>> client.load_system_host_keys()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> client.connect(hostname='172.19.0.120', username='default', password='default', port =2222)
>>> interact = SSHClientInteraction(client, timeout=5, encoding='utf-8', display=True, buffer_size=100000)
>>> prompt = re.escape('.*$  ')
>>> interact.expect(prompt)
CFS:default@Z18044492 [~]$ 
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/paramiko/channel.py", line 683, in recv
    out = self.in_buffer.read(nbytes, self.timeout)
  File "/usr/local/lib/python3.5/dist-packages/paramiko/buffered_pipe.py", line 160, in read
    raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/paramiko_expect.py", line 144, in expect
    current_buffer = self.channel.recv(self.buffer_size)
  File "/usr/local/lib/python3.5/dist-packages/paramiko/channel.py", line 685, in recv
    raise socket.timeout()
socket.timeout
>>>

Please help me on how to solve this issue?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ymkim92commented, Nov 1, 2018

I think I found the problem. As a quick fix, you can change default_match_prefix to ‘.*’ in first expect call:

interact.expect(PROMPT, default_match_prefix='.*')
1reaction
cojayerocommented, Jun 14, 2019

I had the same issue, just changed the prompt on the very first command I send to the remote machine prompt=“AUTO>” interact.send(f"PS1=‘{prompt}’") and keep running

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - paramiko expect timing out - Stack Overflow
I've used regex in there and set it to the exact prompt that it should be seeing and I get the timeout either...
Read more >
paramiko-expect - Python Package Health Analysis - Snyk
The python package paramiko-expect was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as...
Read more >
Channel - Paramiko documentation
A secure tunnel across an SSH Transport . ... Returns the timeout in seconds (as a float) associated with socket operations, or None...
Read more >
pxssh - control an SSH session — Pexpect 4.8 documentation
When the keyword argument timeout is specified as a number, (default: 30), then TIMEOUT will be raised after the value specified has elapsed,...
Read more >
python/4284/paramiko-expect/paramiko_expect.py
device. :param client: A Paramiko SSHClient object. :param timeout: The connection timeout in seconds. : ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found