问题已解决。解决方案在最后。
吐槽一下自己问了个愚蠢的问题。。。。
========================================
报错信息如下:
/bin/python3.8 /home/hrj/PycharmProjects/untitled/test.py
******************************************************************************
* Copyright (c) 2004-2018 New H3C Technologies Co., Ltd. All rights reserved.*
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
******************************************************************************
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 111, in expect_loop
incoming = spawn.read_nonblocking(spawn.maxread, timeout)
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 482, in read_nonblocking
raise TIMEOUT('Timeout exceeded.')
pexpect.exceptions.TIMEOUT: Timeout exceeded.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hrj/PycharmProjects/untitled/test.py", line 40, in
main()
File "/home/hrj/PycharmProjects/untitled/test.py", line 36, in main
child.expect('>')
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 340, in expect
return self.expect_list(compiled_pattern_list,
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 369, in expect_list
return exp.expect_loop(timeout)
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 119, in expect_loop
return self.timeout(e)
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 82, in timeout
raise TIMEOUT(msg)
pexpect.exceptions.TIMEOUT: Timeout exceeded.
command: /usr/bin/ssh
args: ['/usr/bin/ssh', 'admin@172.18.103.10']
buffer (last 100 chars): b'#\r\r\nvlan 101\r\r\n description ILO\r\r\n#\r\r\nvlan 102\r\r\n description CVK_GL\r\r\n#\r\r\nvlan 103\r\r\n---- More ----'
before (last 100 chars): b'#\r\r\nvlan 101\r\r\n description ILO\r\r\n#\r\r\nvlan 102\r\r\n description CVK_GL\r\r\n#\r\r\nvlan 103\r\r\n---- More ----'
after:
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 2864
child_fd: 5
closed: False
timeout: 30
delimiter:
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
0: re.compile(b'>')
Process finished with exit code 1
另外:
child.sendline('display curr')这行改成child.sendline('display th') 就可以正常返回值。
好吧 这是个没过脑子的问题,已经解决了。
问题出在交换机返回的是-----more-----而我匹配的是>所以超时了。