By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

AttributeError while running ssh (from windows) paramiko need help

P: 10
Hi Experts ,

while i am running following demo ssh script of paramiko -->

Expand|Select|Wrap|Line Numbers
  1. import base64
  2. import getpass
  3. import os
  4. import socket
  5. import sys
  6. import traceback
  7.  
  8. import paramiko
  9. import interactive
  10.  
  11.  
  12. # setup logging
  13. paramiko.util.log_to_file('demo_simple.log')
  14.  
  15. # get hostname
  16. username = ''
  17. if len(sys.argv) > 1:
  18.     hostname = sys.argv[1]
  19.     if hostname.find('@') >= 0:
  20.         username, hostname = hostname.split('@')
  21. else:
  22.     hostname = raw_input('Hostname: ')
  23. if len(hostname) == 0:
  24.     print '*** Hostname required.'
  25.     sys.exit(1)
  26. port = 22
  27. if hostname.find(':') >= 0:
  28.     hostname, portstr = hostname.split(':')
  29.     port = int(portstr)
  30.  
  31.  
  32. # get username
  33. if username == '':
  34.     default_username = getpass.getuser()
  35.     username = raw_input('Username [%s]: ' % default_username)
  36.     if len(username) == 0:
  37.         username = default_username
  38. password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
  39.  
  40.  
  41. # get host key, if we know one
  42. hostkeytype = None
  43. hostkey = None
  44. try:
  45.     host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
  46. except IOError:
  47.     try:
  48.         # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
  49.         host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
  50.     except IOError:
  51.         print '*** Unable to open host keys file'
  52.         host_keys = {}
  53.  
  54. if host_keys.has_key(hostname):
  55.     hostkeytype = host_keys[hostname].keys()[0]
  56.     hostkey = host_keys[hostname][hostkeytype]
  57.     print 'Using host key of type %s' % hostkeytype
  58.  
  59.  
  60. # now, connect and use paramiko Transport to negotiate SSH2 across the connection
  61. try:
  62.     t = paramiko.Transport((hostname, port))
  63.     t.connect(username=username, password=password, hostkey=hostkey)
  64.     chan = t.open_session()
  65.     chan.get_pty()
  66.     chan.invoke_shell()
  67.     print '*** Here we go!'
  68.     print
  69.     interactive.interactive_shell(chan)
  70.     chan.close()
  71.     t.close()
  72.  
  73. except Exception, e:
  74.     print '*** Caught exception: %s: %s' % (e.__class__, e)
  75.     traceback.print_exc()
  76.     try:
  77.         t.close()
  78.     except:
  79.         pass
  80.     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@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?!
Dec 13 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.