AttributeError while running ssh (from windows) paramiko need help
Darshak Bavishi
bavishi.darshak at gmail.com
Mon Dec 13 09:14:30 EST 2010
Hi Experts ,
while i am running following demo ssh script of paramiko -->
*import base64*
*import getpass*
*import os*
*import socket*
*import sys*
*import traceback*
*
*
*import paramiko*
*import interactive*
*
*
*
*
*# setup logging*
*paramiko.util.log_to_file('demo_simple.log')*
*
*
*# get hostname*
*username = ''*
*if len(sys.argv) > 1:*
* hostname = sys.argv[1]*
* if hostname.find('@') >= 0:*
* username, hostname = hostname.split('@')*
*else:*
* hostname = raw_input('Hostname: ')*
*if len(hostname) == 0:*
* print '*** Hostname required.'*
* sys.exit(1)*
*port = 22*
*if hostname.find(':') >= 0:*
* hostname, portstr = hostname.split(':')*
* port = int(portstr)*
*
*
*
*
*# get username*
*if username == '':*
* default_username = getpass.getuser()*
* username = raw_input('Username [%s]: ' % default_username)*
* if len(username) == 0:*
* username = default_username*
*password = getpass.getpass('Password for %s@%s: ' % (username, hostname))*
*
*
*
*
*# get host key, if we know one*
*hostkeytype = None*
*hostkey = None*
*try:*
* host_keys =
paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))*
*except IOError:*
* try:*
* # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
*
* host_keys =
paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))*
* except IOError:*
* print '*** Unable to open host keys file'*
* host_keys = {}*
*
*
*if host_keys.has_key(hostname):*
* hostkeytype = host_keys[hostname].keys()[0]*
* hostkey = host_keys[hostname][hostkeytype]*
* print 'Using host key of type %s' % hostkeytype*
*
*
*
*
*# now, connect and use paramiko Transport to negotiate SSH2 across the
connection*
*try:*
* t = paramiko.Transport((hostname, port))*
* t.connect(username=username, password=password, hostkey=hostkey)*
* chan = t.open_session()*
* chan.get_pty()*
* chan.invoke_shell()*
* print '*** Here we go!'*
* print*
* interactive.interactive_shell(chan)*
* chan.close()*
* t.close()*
*
*
*except Exception, e:*
* print '*** Caught exception: %s: %s' % (e.__class__, e)*
* traceback.print_exc()*
* try:*
* t.close()*
* except:*
* pass*
* sys.exit(1)*
It gives error as follows :
*Warning (from warnings module):*
* File "C:\Python26\lib\site-packages\Crypto\Hash\SHA.py", line 6*
* from sha import **
*DeprecationWarning: the sha module is deprecated; use the hashlib module
instead*
*
*
*Warning (from warnings module):*
* File "C:\Python26\lib\site-packages\Crypto\Hash\MD5.py", line 6*
* from md5 import **
*DeprecationWarning: the md5 module is deprecated; use hashlib instead*
*Hostname: 10.135.15.41*
*Username [admin]: root*
*
*
*Warning (from warnings module):*
* File "C:\Python26\lib\getpass.py", line 88*
* return fallback_getpass(prompt, stream)*
*GetPassWarning: Can not control echo on the terminal.*
*Warning: Password input may be echoed.*
*Password for root at 10.135.15.41: alcatel*
**** Unable to open host keys file*
**** Here we go!*
*
*
*Line-buffered terminal emulation. Press F6 or ^Z to send EOF.*
*
*
*
*
*
*
*Last login: Mon Dec 13 19:38:31 2010 from 10.135.19.50*
*
*
*
*
**** Caught exception: <type 'exceptions.AttributeError'>: read*
*Traceback (most recent call last):*
* File "C:\Python26\paramiko-1.7.4\demos\demo_simple.py", line 90, in
<module>*
* interactive.interactive_shell(chan)*
* File "C:\Python26\paramiko-1.7.4\demos\interactive.py", line 36, in
interactive_shell*
* windows_shell(chan)*
* File "C:\Python26\paramiko-1.7.4\demos\interactive.py", line 91, in
windows_shell*
* d = sys.stdin.read(1)*
* File "C:\Python26\lib\idlelib\rpc.py", line 560, in __getattr__*
* raise AttributeError, name*
*AttributeError: read*
*
*
*
*
**** EOF ****
*
*
*Traceback (most recent call last):*
* File "C:\Python26\paramiko-1.7.4\demos\demo_simple.py", line 101, in
<module>*
* sys.exit(1)*
*SystemExit: 1*
*
*
*can you tell me what is use of Hostkey and how to overcome this issue?!*
--
BR
Darshak Bavishi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101213/bda71c5a/attachment-0001.html>
More information about the Python-list
mailing list