Paramiko“未知服务器" [英] Paramiko "Unknown Server"
本文介绍了Paramiko“未知服务器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Paramiko库,但是一旦尝试连接以下简单程序,该库就会引发异常:
I'm trying to get started with the Paramiko library, but the library is throwing an exception as soon as I try to connect with the following simple program:
import paramiko
ssh = paramiko.SSHClient()
ssh.connect('127.0.0.1', username='boatzart', password='mypassword')
我得到的错误是:
Traceback (most recent call last):
File "test.py", line 6, in <module>
ssh.connect('127.0.0.1')
File "build/bdist.macosx-10.7-intel/egg/paramiko/client.py", line 316, in connect
File "build/bdist.macosx-10.7-intel/egg/paramiko/client.py", line 85, in missing_host_key
paramiko.SSHException: Unknown server 127.0.0.1
无论我尝试使用哪台服务器,都会发生这种情况.
This occurs no matter which server I try.
推荐答案
由于缺少主机密钥而引发了异常,线索很神秘,因为未知服务器"是从missing_host_key
The exception was raised because you are missing a host key, the rather cryptic "Unknown server" is the clue - since the exception was raised from missing_host_key
尝试以下方法:
import paramiko
paramiko.util.log_to_file('ssh.log') # sets up logging
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('127.0.0.1', username=username, password=password)
stdin, stdout, stderr = client.exec_command('ls -l')
这篇关于Paramiko“未知服务器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文