KpyM Telnet/SSH Server - Forum
Unable to connect to SSH server using python/paramiko |
Brian |
Unable to connect to SSH server using python/paramiko |
Apr 15 2010 19:47 |
|
I'm trying to connect to a KpyM server I have set up using an SSH library for python (paramiko) that has worked well in the past.
I use the following code and get an SSHException. Using Putty, I am able to connect to the same host. I'm hoping it's something very obvious that I'm missing. Any ideas on how to proceed with this?
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect(my_host, username=my_username, password=my_password, key_filename=None)
Traceback (most recent call last):
File "<pyshell#23>", line 1, in -toplevel-
ssh.connect(my_host, username=my_username, password=my_password, key_filename=None)
File "C:\Python24\lib\site-packages\paramiko\client.py", line 327, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "C:\Python24\lib\site-packages\paramiko\client.py", line 481, in _auth
raise saved_exception
SSHException: No existing session
>>>
|
Kroum Grigorov |
|
May 13 2010 08:23 |
|
Just made a quick test running Python 2.6/Paramiko 1.7.5(with the ipv4 fix applied) on Windows against KTS 1.18a it seems to work OK with interactive sessions (SShClient.invoke_shell)
I have not tested non interactive sessions but I do NOT expect them to work.
Kroum
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('127.0.0.1', username='user', password='password', key_filename=None)
chan = ssh.invoke_shell(term='vt100', width=80, height=24)
time.sleep(3)
chan.send('\r\n')
time.sleep(3)
chan.send('\r\n')
chan.recv(1000)
time.sleep(5)
chan.send('\r\n')
chan.recv(1000)
chan.send('dir\r\n')
time.sleep(1)
chan.recv(1000)
chan.send('exit\r\n')
|
Will |
|
Mar 04 2014 16:18 |
|
I am also having this same error:
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('172.16.11.141', username=''my_user', password='my_pass')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/paramiko/client.py", line 342, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/Library/Python/2.7/site-packages/paramiko/client.py", line 533, in _auth
raise saved_exception
paramiko.SSHException: No existing session
I am pretty annoyed because I just paid $35 for this and now it does not work at all for my use case. :(
I guess I will have to work with freeSSHd after all. I really wanted to use this library...
|
Angels |
|
Mar 06 2014 11:37 |
|
Hello,
I have a similar problem with paramiko. I can invoke_shell or exec_command, but I can't read the pipe for none of them.
Sometimes I can read the commands sent if I open another instance of python and connect to the same host, invoke_shell and then chan.recv(), but never the responses of the commands I send.
Using putty everything works perfect, but I need to run python!!
Of course I'm also annoyed to have paid the $35 and not being able to use it!
|
topin89 |
|
May 06 2014 08:22 |
|
Looks like KPyM don't support multiple sessions used by exec_command
So I have to use terminal emulation
import paramiko
import time
host = '192.168.79.210'
user = 'user'
secret = 'password'
port = 22
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=host, username=user, password=secret, port=port)
channel=client.get_transport().open_session() #the only session available. Socket-like object
channel.get_pty();#Requesting "terminal"
time.sleep(5.5); #Yeah, free version
channel.send(u'1')#Pressing anykey
a=channel.recv(10000);
print a.decode('utf-8');
channel.send('dir\r\n')
a=channel.recv(10000);
print a.decode('utf-8');
channel.send('exit\r\n')
a=channel.recv(10000);
print a.decode('utf-8');
client.close()
|
lewl |
|
Jun 29 2015 08:46 |
|
lewl
|
© 2007 - 2008 Kroum Grigorov
|
|