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

Fail to re-use SSH session when connecting to Cisco C2960 switcher #55

Closed
yegle opened this issue Nov 16, 2011 · 5 comments
Closed

Fail to re-use SSH session when connecting to Cisco C2960 switcher #55

yegle opened this issue Nov 16, 2011 · 5 comments

Comments

@yegle
Copy link

yegle commented Nov 16, 2011

Here's my code:

#!/usr/bin/python26

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('1.2.3.4',username='xxx', password='xxxx',allow_agent=False)
stdin, stdout, stderr = ssh.exec_command('show version')
stdin, stdout, stderr = ssh.exec_command('show mac brief')

result in:

Traceback (most recent call last):
  File "./test.py", line 10, in <module>
    stdin, stdout, stderr = ssh.exec_command('show mac brief')
  File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 363, in exec_command
    chan = self._transport.open_session()
  File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 658, in open_session
    return self.open_channel('session')
  File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 746, in open_channel
    raise e
EOFError
@msuberrivs
Copy link

I got this problem too. How did you fix it?

@urban-1
Copy link

urban-1 commented Apr 16, 2015

Hi all,

I got this too...

A workaround is to use invoke_shell and work the returned channel like expect: set a time-out and read until you get the prompt. Don't forget to read/empty the buffer after login (and do terminal length 0)! This works for Alcatel too (with env no more) but I think in this case it fails from the 1st issued command (I don't remember, I can test and come back to this if needed). Also, debugging a bit the channel created by invoke_shell I noticed that the characters are returned 1-by-1 - not sure if it is relevant... but the channel timeout seems to not reset when a character is received (the timeout is for the whole process and the channel will close even if the device is still sending characters - I have to test this more)

It would be really good to see this fixed since detecting prompts is very hacky and time-out has to be tuned for specific commands (Alcatel admin display-config takes more than 2 minutes in some cases).

Andreas

(Testing with python 2.7 and 3.4)

@zodiacsmash
Copy link

The most likely reason for the EOFError is that the device does not support an SSH channel 'exec' request - which is what exec_command() is attempting - and drops the connection.

The Cisco documentation for 2960-C SSH capability states (under limitations) that :

"SSH supports only the execution-shell application"

which presumably means that - as mentioned above - invoke_shell() is the Paramiko command to use. For details on this I searched for Paramiko SSH Network Devices and found some useful resources.

@bskinn
Copy link
Contributor

bskinn commented May 2, 2023

@jun66j5 -- if this issue is also due to a Cisco-specific behavior, should we close it also?

@jun66j5
Copy link
Contributor

jun66j5 commented May 2, 2023

@bskinn Yes. We should close it also. That is an issue of Cisco device, not an issue of ssh client.

@bskinn bskinn closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants