我正在使用 pysftp 包(版本 0.2.9)运行 Python 3。
我的以下代码在这里。我正在正确加载主机密钥,如行所示cnopts.hostkeys.keys()
。
import pysftp
key_file_test = './path_to_key_file/key_file.pub'
DOWNLOAD_UAT = {
"USERNAME": "xxxxxxxx",
"PASSWORD": "xxxxxxxx"
}
UAT_FTP_SITE = 'sftp-test.site.com'
cnopts = pysftp.CnOpts()
cnopts.hostkeys.load(key_file_test)
cnopts.hostkeys.keys()
'''['github.com', 'XXX.XX.XXX.XXX', 'sftp-test.site.com']'''
srv = pysftp.Connection(host=UAT_SFTP_SITE, username=DOWNLOAD_UAT['USERNAME'],
password=DOWNLOAD_UAT['PASSWORD'], cnopts=cnopts, port=22)
然后我运行最后一行时的错误是
---------------------------------------------------------------------------
SSHException Traceback (most recent call last)
<ipython-input-82-308ec955a92e> in <module>()
8
9 srv = pysftp.Connection(host=UAT_SFTP_SITE, username=DOWNLOAD_UAT['USERNAME'],
---> 10 password=DOWNLOAD_UAT['PASSWORD'], cnopts=cnopts, port=22)
11 data = srv.listdir()
C:\ProgramData\Anaconda3\lib\site-packages\pysftp\__init__.py in __init__(self, host, username, private_key, password, port, private_key_pass, ciphers, log, cnopts, default_path)
141 self._transport.use_compression(self._cnopts.compression)
142 self._set_authentication(password, private_key, private_key_pass)
--> 143 self._transport.connect(**self._tconnect)
144
145 def _set_authentication(self, password, private_key, private_key_pass):
C:\ProgramData\Anaconda3\lib\site-packages\paramiko\transport.py in connect(self, hostkey, username, password, pkey, gss_host, gss_auth, gss_kex, gss_deleg_creds)
1139 key.get_name(), repr(key.asbytes()))
1140 )
-> 1141 raise SSHException('Bad host key from server')
1142 self._log(DEBUG, 'Host key verified (%s)' % hostkey.get_name())
1143
SSHException: Bad host key from server
有谁知道这里有什么问题?