473,387 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

AttributeError while running ssh (from windows) paramiko need help

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
0 1545

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

Similar topics

13
by: EggsAckley | last post by:
Hi: I have a file that I have been told is a SQL Server backup from a server somewhere. The file is about 200MB in size I am trying to create the database on my local server using RESTORE. I...
12
by: LongBow | last post by:
Hello all, From doing a google serach in the newsgroups I found out that a string can't be returned from a function, but using a char* I should be able to do it. I have spent most of the day...
2
by: Thomas | last post by:
Hi, I used xsd.exe to generate a *.xsd file from the *.xml-File and then I created a typed DataSet in VisualStudio 2003 But now I have problems to read the data from the DataSet. <?xml...
0
by: Vuong | last post by:
I just wrote a simple host application. Already tested. After that i change it to a service. (I add new project to the exist host application, copy code from this host application to OnStart() of...
3
by: Harry Simpson | last post by:
Windows Server 2003 is supposed to include Framework 1.1 right. I don't have it here but have reports that the web is not running. The users say that the %COMPUTERNAME%\ASPNET user doesn't exist....
1
by: Learner | last post by:
Hi there, I have installed Sql server 2005 developer on my machine which already has a Sql server 2000 installed on. Now i am trying to query the Sqlserver 2005 data(Ex: from Person.Address...
1
by: puttaramakrishna | last post by:
Hi Folks, How to connect from windows to linux using ssh without username/passwd. With this scenario, i need to write a program on python. Regards, Ramakrishna.
11
by: Paulo da Silva | last post by:
I would like to implement something like this: class C1: def __init__(self,xxx): if ... : self.foo = foo self.bar = bar else: self=C1.load(xxx)
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
0
by: =?Utf-8?B?UGF1bCBIYWdlcg==?= | last post by:
I've been trying to solve this issue for the better part of a month. My attempts to get an answer on the MSDN groups proved to no avail. Here is the situation/problem. I am migrating an old...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.