python - 'HostKeys' object has no attribute 'has_key' -
i m way upload files on sftp using paramiko getting error.
ri@ri-desktop:~/workspace/ssh$ python testssh.py traceback (most recent phone call last): file "testssh.py", line 75, in if host_keys.has_key(hostname): attributeerror: 'hostkeys' object has no attribute 'has_key'
this code within test.py
hostkeytype = none hostkey = none files_copied = 0 try: host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))<br/> except ioerror: try: # seek ~/ssh/ too, e.g. on windows host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts')) except ioerror: print '*** unable 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 {0}'.format(hostkeytype) paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts')) paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
either 1 of these functions runs , returns object doesn't have has_key attribute, or you're using python 3, has_key has been removed dicts.
since using python 2.x, problem should these functions homecoming doesn't have has_key attribute
i had @ source code paramiko.util , indeed, util.load_host_keys returns else dict, namely hostkeys object not implement has_key(), cannot phone call function on host_keys object
because docstring hostkeys class says this
a .hostkeys object can treated dict; dict lookup equivalent calling lookup.
you utilize instead
if hostname in host_keys: python paramiko
No comments:
Post a Comment