exscript icon indicating copy to clipboard operation
exscript copied to clipboard

Expect and waitfor error with ValueError

Open sjstewart opened this issue 2 years ago • 7 comments

I'm trying to connect to a telnet server that has a Linux system connected to it, issue a newline character, and use either waitfor or expect (something using regular expressions) to match and get the output. I am able to get this to work consistently using read_until:

tn.read_until(b'#', 5) '' tn.read_until(b'#', 5) '# hithere\r\nroot@localhost:~# '

However, expect gives me this "negative seek position" error:

tn.expect(['#'], 1) Traceback (most recent call last): File "", line 1, in File "/u/stewarts/.local/lib/python3.7/site-packages/Exscript/protocols/telnetlib.py", line 752, in expect return self._waitfor(relist, timeout, True, cleanup=cleanup) File "/u/stewarts/.local/lib/python3.7/site-packages/Exscript/protocols/telnetlib.py", line 691, in _waitfor self.cookedq.seek(qlen - search_window_size) ValueError: Negative seek position -150

After seeing telnetlib is deprecated I was looking for a drop in replacement and this seemed the closest.

Edit: I think this is using exscript 2.6.28 and it is on Debian 10 with python 3.7.3

sjstewart avatar Apr 19 '23 20:04 sjstewart

Can you try if the problem also exists in Version a48030c?

knipknap avatar Apr 19 '23 21:04 knipknap

It looks like the version I'm using does have that change to collections.py.

sjstewart avatar Apr 20 '23 18:04 sjstewart

Every version since does ;-), but the question was whether you have the same problem with the version from this particular commit. Because there were some changes after that that may have caused the problem.

knipknap avatar Apr 20 '23 20:04 knipknap

Ahhh, gotcha. I checked out the code as of that commit and gave it another try, it looks like it happens the same:

tn.write(b'# testing\n') tn.expect(['#'],1) Traceback (most recent call last): File "", line 1, in File "/u/stewarts/.local/lib/python3.7/site-packages/Exscript/protocols/telnetlib.py", line 705, in expect return self._waitfor(relist, timeout, True, cleanup=cleanup) File "/u/stewarts/.local/lib/python3.7/site-packages/Exscript/protocols/telnetlib.py", line 644, in _waitfor self.cookedq.seek(qlen - search_window_size) ValueError: Negative seek position -150 tn.waitfor(['#'],1) Traceback (most recent call last): File "", line 1, in File "/u/stewarts/.local/lib/python3.7/site-packages/Exscript/protocols/telnetlib.py", line 698, in waitfor return self._waitfor(relist, timeout, False, cleanup) File "/u/stewarts/.local/lib/python3.7/site-packages/Exscript/protocols/telnetlib.py", line 644, in _waitfor self.cookedq.seek(qlen - search_window_size) ValueError: Negative seek position -150

sjstewart avatar Apr 21 '23 20:04 sjstewart