I am trying to pass 2 precompiled regular expressions to the python telnetlib wait method, but I get: TypeError: you cannot use a string pattern for a byte-like object. Sample code below:
import re,sys,telnetlib tn=telnetlib.Telnet('localhost',23,10) re_list=[re.compile("login:",re.I),re.compile("username:",re.I)] print("re_list:",re_list)
Example output below:
python tn_exp_bug.py re_list: [<_sre.SRE_Pattern object at 0x00A49E90>, <_sre.SRE_Pattern object at 0x00A6CB60>] Traceback (most recent call last): File "tn_exp_bug.py", line 8, in <module> index,obj,data=tn.expect(re_list,10) File "c:\python33\lib\telnetlib.py", line 652, in expect return self._expect_with_select(list, timeout) File "c:\python33\lib\telnetlib.py", line 735, in _expect_with_select m = list[i].search(self.cookedq) TypeError: can't use a string pattern on a bytes-like object</pre>
Other information: I work on Windows XP, Python version 3.3.0. I checked bugs.python.org, and there is only 1 open error for telnet that does not seem to be relevant at all.
source share