telnetlib strange behavior?

Robert Roy rjroy at takingcontrol.com
Tue Jun 13 19:03:29 EDT 2000


On Mon, 12 Jun 2000 18:20:11 GMT, bragib at my-deja.com wrote:

>I am trying to telnet from a UNIX box to an NT to get the doskeys.
>The NT that I login to runs a couple of .bat scripts which clear the
>screen set up some stuff etc.  When I try to do a read_all() it fails
>the first time with the exception:
>Traceback (innermost last):
>  File "telnet.py", line 17, in ?
>    tn.read_all()
>  File "/usr/abaqus60/5-0_copy/source/Python/Lib/telnetlib.py", line
>229, in read_all
>    self.fill_rawq()
>  File "/usr/abaqus60/5-0_copy/source/Python/Lib/telnetlib.py", line
>367, in fill_rawq
>    buf = self.sock.recv(50)
>socket.error: (131, 'Connection reset by peer')
>
>
>That is why I put the first try in a try: except: clause.  The second
>time I try to do a read_all() it works fine but I don't get all the keys
>I am missing some of the first keys.  I assume that the first read_all()
>actually did read some stuff and then the second read got the rest.
>
>Can anyone see anything obviously wrong with this.
>
>
>Thanks, Bragi
>
>import sys
>import telnetlib
>HOST = 'shadow'
>USER = 'bragi'
>tn = telnetlib.Telnet(HOST)
>tn.open(HOST)
>tn.read_until("login: ")
>tn.write(USER+'\r')
>tn.read_until("password: ")
>tn.write('my_password\r')
>tn.write('doskey /macros\r')
>tn.write('exit\r')
>print 'done'
>try:
>    all1 = tn.read_all()
>except:
>    pass
>all = tn.read_all()
>print all
>

The documentation for telnetlib is confusing. What is does not state
is that if you supply a hostname when you instantiate an instance of
Telnet() that it will open the instance. What it does tell you however
is not to try to re-open a connected instance... (see the source code
for __init__ and the docstring for open.

You are doing :
>tn = telnetlib.Telnet(HOST)
>tn.open(HOST)

Perhaps that is causing the problem. I can't get telnetlib to work on
either of my machines.

Bob




More information about the Python-list mailing list