title: EOF when using pexpect and pxssh
body: <p>I'm trying to run the code in the <em>Interacting with SSH Through Pexpect</em> and <em>Brute Forcing SSH Passwords with Pxssh</em> sections from Chapter 2 of <a href="http://shop.oreilly.com/product/9781597499576.do" rel="noreferrer">Violent Python</a>. Using both <code>child.expect()</code> and <code>pxssh</code> I get similar EOF errors.</p>
  
  <p>Running these commands from the Python console:</p>
  
  <pre><code>import pexpect
  connStr = "ssh root@127.0.0.1"
  child = pexpect.spawn(connStr)
  ret = child.expect([pexpect.TIMEOUT, ssh_newkey, "[P|p]assword:"])
  </code></pre>
  
  <p>I get this output:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
  ne 1316, in expect
      return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
  ne 1330, in expect_list
      return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
  ne 1401, in expect_loop
      raise EOF (str(e) + '\n' + str(self))
  EOF: End Of File (EOF) in read_nonblocking(). Empty string style platform.
  &lt;pexpect.spawn object at 0x10180c550&gt;
  version: 2.4 ($Revision: 516 $)
  command: /usr/bin/ssh
  args: ['/usr/bin/ssh', 'root@127.0.0.1']
  searcher: searcher_re:
      0: TIMEOUT
      1: re.compile("Are you sure you want to continue connecting")
      2: re.compile("[P|p]assword:")
  buffer (last 100 chars): 
  before (last 100 chars): 
  after: &lt;class 'pexpect.EOF'&gt;
  match: None
  match_index: None
  exitstatus: 255 
  flag_eof: True
  pid: 12122
  child_fd: 4
  closed: False
  timeout: 30
  delimiter: &lt;class 'pexpect.EOF'&gt;
  logfile: None
  logfile_read: None
  logfile_send: None
  maxread: 2000
  ignorecase: False
  searchwindowsize: None
  delaybeforesend: 0.05
  delayafterclose: 0.1
  delayafterterminate: 0.1
  </code></pre>
  
  <p>And running these commands, using <code>pxssh</code>:</p>
  
  <pre><code>import pxssh
  s = pxssh.pxssh()
  s.login("127.0.0.1", "root", "1234")
  </code></pre>
  
  <p>I get this output:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pxssh.py", line
   196, in login
      i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:pas
  sword)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connectio
  n closed by remote host"], timeout=login_timeout)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
  ne 1316, in expect
      return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
  ne 1330, in expect_list
      return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
  ne 1401, in expect_loop
      raise EOF (str(e) + '\n' + str(self))
  EOF: End Of File (EOF) in read_nonblocking(). Empty string style platform.
  &lt;pxssh.pxssh object at 0x1016bff90&gt;
  version: 2.4 ($Revision: 516 $)
  command: /usr/bin/ssh
  args: ['/usr/bin/ssh', '-q', '-l', 'root', '127.0.0.1']
  searcher: searcher_re:
      0: re.compile("(?i)are you sure you want to continue connecting")
      1: re.compile("[#$]")
      2: re.compile("(?i)(?:password)|(?:passphrase for key)")
      3: re.compile("(?i)permission denied")
      4: re.compile("(?i)terminal type")
      5: TIMEOUT
      6: re.compile("(?i)connection closed by remote host")
  buffer (last 100 chars): 
  before (last 100 chars): 
  after: &lt;class 'pexpect.EOF'&gt;
  match: None
  match_index: None
  exitstatus: None
  flag_eof: True
  pid: 12136
  child_fd: 3
  closed: False
  timeout: 30
  delimiter: &lt;class 'pexpect.EOF'&gt;
  logfile: None
  logfile_read: None
  logfile_send: None
  maxread: 2000
  ignorecase: False
  searchwindowsize: None
  delaybeforesend: 0.05
  delayafterclose: 0.1
  delayafterterminate: 0.1
  </code></pre>
  
  <p>I get similar results when I substitute <em>127.0.0.1</em> with other hosts and try different username/password combinations.</p>
  
  <p>The <a href="http://pexpect.sourceforge.net/doc/" rel="noreferrer">pexpect documentation</a> suggests using <code>expect(pexpect.EOF)</code> to avoid generating the EOF exception. Indeed, when I do the following:</p>
  
  <pre><code>connStr = "ssh root@127.0.0.1"
  child = pexpect.spawn(connStr)
  print child.expect(pexpect.EOF)
  </code></pre>
  
  <p>The result is <code>0</code>.</p>
  
  <p>But the following questions remain:</p>
  
  <ol>
  <li>I'm confused by the book's syntax: <code>child.expect([pexpect.TIMEOUT, ssh_newkey, "[P|p]assword:"])</code>. Why are we passing a list to <code>expect()</code>? What is this list supposed to contain?</li>
  <li>How do I make use of <code>expect(pexpect.EOF)</code>, as the documentation instructs, when using pxssh?</li>
  <li>Why does the code in the book not work properly? Has something changed in the pexpect library since the book's publication? Is it because I am on OS X?</li>
  </ol>
  
  <p>I have Python 2.7 and pexpect 2.4 running on Mac OS X 10.8.4.</p>