Paramiko、Python、SSH、路由器登录的Unittest错误
在我的测试设置中,我编写了一个小的单元测试,它只运行到路由器的登录。如果发生这种情况,则测试通过 当前问题,我无法通过IP地址连接。请参阅输出后的错误消息 功能:Paramiko、Python、SSH、路由器登录的Unittest错误,python,python-3.x,ssh,paramiko,python-unittest,Python,Python 3.x,Ssh,Paramiko,Python Unittest,在我的测试设置中,我编写了一个小的单元测试,它只运行到路由器的登录。如果发生这种情况,则测试通过 当前问题,我无法通过IP地址连接。请参阅输出后的错误消息 功能: import unittest import paramiko class SimpleWidgetTestCase(unittest.TestCase): #This class inherits unittest.TestCase #----------------SETUP---------------- #s
import unittest
import paramiko
class SimpleWidgetTestCase(unittest.TestCase): #This class inherits unittest.TestCase
#----------------SETUP----------------
#setup will run first
def setUp(self):
self.ssh = paramiko.SSHClient()
#self.ssh.load_system_host_keys()
self.ssh.connect(hostname='xxx.xx.xx.250', username='xxxx', password='xxxx')
#-----------------TEST--------------------
#test cases goes here with 'test' prefix
def test_split(self):
#code here
pass
#this will run after the test cases
def tearDown(self):
#your code to clean or close the connection
pass
if __name__ == '__main__':
unittest.main()
问题:
======================================================================
ERROR: test_split (__main__.SimpleWidgetTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:/Python37/Lib/py3-testcore/Switch_Test/Complete/TD_refactor/_test_account_disable_enable.py", line 11, in setUp
self.ssh.connect(hostname='xxx.xx.xxx.xxx', username='xxxx', password='xxxx')
File "C:\Python37\lib\site-packages\paramiko\client.py", line 402, in connect
self, server_hostkey_name, server_key
File "C:\Python37\lib\site-packages\paramiko\client.py", line 768, in missing_host_key
'Server {!r} not found in known_hosts'.format(hostname)
paramiko.ssh_exception.SSHException: Server 'xxx.xxx.xxx.xxxx' not found in known_hosts
----------------------------------------------------------------------
Ran 1 test in 2.002s
FAILED (errors=1)
Process finished with exit code 1
self.ssh.set_缺少主机_密钥_策略(paramiko.AutoAddPolicy())
在连接之前添加此行。这可能会解决你的问题