pexpect.EOF:文件结束(EOF)。异常风格平台

时间:2016-09-18 13:03:55

标签: python-2.7 pexpect

随着时间的推移,我正在催生孩子的过程,并且正在做着什么' ssh'遥控盒。它从最近几天开始工作正常,现在突然间,每当我想要产生子进程时,它都会抛出错误。不知道发生了什么事。

直到现在我正在使用pexpect 3.1,我遇到了这个问题。所以我把它升级到3.2,但仍面临同样的问题。

>>> child = pexpect.spawn('ssh -o StrictHostKeyChecking=no centos@192.168.2.23')
>>> child.expect([pexpect.TIMEOUT,'[P|p]assword: '])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1418, in expect
    timeout, searchwindowsize)
  File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1433, in expect_list
    timeout, searchwindowsize)
  File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1521, in expect_loop
    raise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Exception style platform.
<pexpect.spawn object at 0x7fe923a8b710>
version: 3.2
command: /usr/bin/ssh
args: ['/usr/bin/ssh', '-o', 'StrictHostKeyChecking=no', 'centos@192.168.2.23']
searcher: <pexpect.searcher_re object at 0x7fe923a8b750>
buffer (last 100 chars): ''
before (last 100 chars): 'AL PROSECUTION.\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).\r\r\n'
after: <class 'pexpect.EOF'>
match: None
match_index: None
exitstatus: 255
flag_eof: True
pid: 2202
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

2 个答案:

答案 0 :(得分:1)

错误实际上在ssh命令执行中。好像你需要一个ssh密钥来连接:

before (last 100 chars): 'AL PROSECUTION.\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).\r\r\n'

解决此问题的最简单方法是手动运行ssh -o StrictHostKeyChecking=no centos@192.168.2.23并修复ssh密钥问题。

答案 1 :(得分:1)

child.expect([pexpect.TIMEOUT, 'pattern', pexpect.EOF])
  

当您尝试从EOF状态的文件描述符中读取时,某些UNIX平台将引发异常。相反,其他UNIX平台则静默返回一个空字符串以指示已达到EOF状态。
  如果您希望在不产生EOF异常的情况下阅读孩子的输出的末尾,请使用expect(pexpect.EOF)方法。

有关详细信息,您可以关注this

希望对您有帮助。