Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sudden Problem with pexpect
I have a script the uses pexpect that has been working for years (common story, right?) that suddenly is failing. When I run the command manually I first get a prompt for 'Username'. When I run the pexpect script I get a trace back.

proc=pexpect.spawn('/usr/sbin/openvpn '+config)
Traceback (most recent call last): File "/usr/local/bin/", line 89, in <module> proc=portOpen(configFile[useConfig]) File "/usr/local/bin/", line 47, in portOpen proc.expect('Username:') File "/usr/lib/python2.7/site-packages/", line 1311, in expect return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) File "/usr/lib/python2.7/site-packages/", line 1325, in expect_list return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) File "/usr/lib/python2.7/site-packages/", line 1396, in expect_loop raise EOF (str(e) + '\n' + str(self)) pexpect.EOF: End Of File (EOF) in read_nonblocking(). Exception style platform. <pexpect.spawn object at 0x7f5d9121c7d0> version: 2.3 ($Revision: 399 $) command: /usr/sbin/openvpn args: ['/usr/sbin/openvpn'] searcher: searcher_re: 0: re.compile("Username:") buffer (last 100 chars): before (last 100 chars): d *BEFORE* this. General Standalone Options: --show-gateway : Show info about default gateway. after: <class 'pexpect.EOF'> match: None match_index: None exitstatus: None flag_eof: True pid: 6653 child_fd: 4 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
One thing I noticed is that the username prompt is in bold. (not sure if it has always been that way) I don't think that would cause the problem but I though I'd mention it. If that somehow changed the string so it doesn't match I would expect a different error.

I could probably figure this out if I understood what this traceback was telling me. Can someone interpret it for me? TIA.
It was reading from the program trying to find your expected string. But then the program gave back an EOF (it exited). And the last few things that it received before exiting was:

Quote: d *BEFORE* this.

General Standalone Options:
--show-gateway : Show info about default gateway.

Do you recognize the output? Can your openvpn produce that output somehow?

I suspect that the stuff in config is making the command line invalid and it's just showing you the usage information rather than spawning.
Hmm. That is not what I get from manually launching. Thanks. At least you gave me a direction to look.
(Nov-19-2021, 04:56 PM)gw1500se Wrote: Hmm. That is not what I get from manually launching. Thanks. At least you gave me a direction to look.

What is the content of config?

Can you just see something happen with

import subprocess
print(subprocess.getoutput('/usr/sbin/openvpn '+config))

Possibly Related Threads…
Thread Author Replies Views Last Post
  Not able to read the text using pexpect/expect Bipinjohnson 7 290 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  How to use pexpect in python? tiho_bg 1 405 Oct-30-2021, 02:50 PM
Last Post: Yoriz
  Pexpect timesout before executing whole output eagerissac 0 423 Jun-23-2021, 03:30 AM
Last Post: eagerissac
  Reading and storing a line of output from pexpect child eagerissac 0 696 Jun-17-2021, 12:22 PM
Last Post: eagerissac
  pexpect startup help korenron 2 1,491 Apr-27-2021, 07:23 AM
Last Post: korenron
  Problem with pexpect.exception.TimeOUT korenron 0 861 Apr-12-2021, 03:25 PM
Last Post: korenron
  Request help on pexpect rsurathu 4 2,147 Jul-19-2020, 03:35 PM
Last Post: snippsat
  SIGWINCH ignored when trying to start a screen with the pexpect module StatTark 0 759 Jul-06-2020, 10:12 AM
Last Post: StatTark
  PIP sudden ssl error erickroberts 5 5,042 May-19-2020, 03:58 PM
Last Post: pmpinaki
  Collecting Output from Pexpect gw1500se 3 1,979 Jul-20-2019, 08:42 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020