[Tutor] telnetlib - character hex00 missing
Alan Gauld
alan.gauld at btinternet.com
Mon Nov 22 10:07:06 CET 2010
"Joachim Roop" <no.dr at gmx.de> wrote
> Even though my non-python telnet-server on the other side is
> sending #00-bytes, they are not recognized by python's telnetlib
> (characters #01-#FF seem to work fine though).
> My C++ implementation has no problems with this.
> I have to use Python 3.1 on Windows.
>
> I'm guessing this a known bug. What is the workaround? :(
Telnetlib has been around for at least 10 years so I'd expect a
bug that serious to have been fixed long ago! I suspect something
else is at fault.
> # Receiver
> tn = telnetlib.Telnet()
> tn.open(ip, port)
>
> while 1:
Aside:
Python idiom nowadays prefers "while True:" to "while 1:"
> response = (tn.read_until(b"\r",20))[1:-1]
It might be worth breaking this line down and printing the results
data = tn.read_until(b"\r",20) # did telnet even read the 00?
response = data[1:-1] # did we strip it correctly?
> if response.find(bytes.fromhex("00")) > -1:
> print ("There are hex00 characters")
> else:
> print ("No hex00 characters found")
>
> tn.close
Others may have more info, but I'll be surprised if telnetlib can't
read a '00'.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list