Expect() from telnetlib giving me problems.

Eddie Corns eddie at holyrood.ed.ac.uk
Fri Sep 13 07:45:47 EDT 2002

mnations at airmail.net (Marc) writes:


>This is the error I'm getting:

>Exception in thread Thread-3:

>Traceback (most recent call last):
>  File "C:\Python22\lib\threading.py", line 408, in __bootstrap
>    self.run()
>  File "C:\Python22\lib\threading.py", line 396, in run
>    apply(self.__target, self.__args, self.__kwargs)
>  File "main.py", line 85, in run
>    command[0](*command[1:3])
>  File "key.py", line 94, in command
>    read_result(conn)
>  File "key.py", line 104, in read_result
>    buffer = conn.expect(alist, 5)
>  File "C:\python22\lib\telnetlib.py", line 541, in expect
>    list[i] = re.compile(list[i])
>  File "C:\Python22\lib\sre.py", line 178, in compile
>    return _compile(pattern, flags)
>  File "C:\Python22\lib\sre.py", line 228, in _compile
>    raise error, v # invalid expression
>error: nothing to repeat

>I've tried several different ways to get the expect command to work. I
>can't find any examples and only limited documentation. Here is how
>I'm trying to implement it:

>    alist = [ 'COMPLD', '*/' ]
>    buffer = conn.expect(alist, 5)

>Can someone please tell me what is wrong or provide me with some
>working examples of using the command.

As previously mentioned '*/' is not a regular expression.  If you want to
search for fixed strings without bothering to learn abot regular expressions
or if you're not sure exactly what the input will be and whether it may
contain special characters you could do:

  import re
  alist = map (re.escape, [ 'COMPLD', '*/' ])


More information about the Python-list mailing list