当我正在运行Below Given Pyhton代码时,我遇到了身份验证问题,虽然它运行正常,直到我安装python argparse模块,但不知道什么是坏了。
Python 2.6.6
$python gopy4.py
Traceback (most recent call last):
File "./.gopy4.py", line 20, in <module>
client.connect(HOST, username=USER, password=PASSWORD)
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 322, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 476, in _auth
raise saved_exception
paramiko.AuthenticationException: Authentication failed.
下面是Scripts,它工作了几分钟,当我安装argparse时,它抛出上面的错误。
$ cat .gopy4.py
#!/usr/bin/env python
import sys
sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
import paramiko as pm
sys.stderr = sys.__stderr__
import os
class AllowAllKeys(pm.MissingHostKeyPolicy):
def missing_host_key(self, client, hostname, key):
return
HOST = '192.1.10.1'
USER = 'karn'
PASSWORD = 'mypass'
client = pm.SSHClient()
client.load_system_host_keys()
client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
client.set_missing_host_key_policy(AllowAllKeys())
client.connect(HOST, username=USER, password=PASSWORD)
channel = client.invoke_shell()
stdin = channel.makefile('wb')
stdout = channel.makefile('rb')
stdin.write('''
hostname
uname -a
uptime
who
exit
''')
print stdout.read()
stdout.close()
stdin.close()
client.close()
安装截屏....
$ sudo rpm -ivh python-argparse-1.2.1-2.1.el6.noarch.rpm
[sudo] password for karn:
warning: python-argparse-1.2.1-2.1.el6.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:python-argparse ########################################### [100%]
答案 0 :(得分:0)
HOST = '192.1.10.1'
中有一个反引号字符,这就是原因,现在运行正常。