在我的测试设置中,我编写了一个小的unittest,它只运行到路由器的登录。如果这种情况发生得很好,测试就通过了。你知道吗
当前问题,我无法通过IP地址连接。请参阅输出后的错误消息。你知道吗
功能:
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_missing_host_key_policy(paramiko.AutoAddPolicy())
连接前添加此行。这也许能解决你的问题。你知道吗
相关问题 更多 >
编程相关推荐