[Tutor] telnetlib's read_very_eager() method?

James Hartley jjhartley at gmail.com
Wed Sep 14 21:44:06 CEST 2011


I'm trying to programmatically create a telnet session.  Within the
interactive environment, this appears to work very well as server messages
can be saved as strings:

$ python
Python 2.7.1 (r271:86832, Sep  3 2011, 01:32:33)
[GCC 4.2.1 20070719 ] on openbsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> import telnetlib
>>> tn = telnetlib.Telnet('gmail-smtp-in.l.google.com', 25)
>>> s = tn.read_very_eager()
>>> print s
220 mx.google.com ESMTP r70si1582241yhm.54

>>> tn.write("helo\n")
>>> s = tn.read_very_eager()
>>> print s
250 mx.google.com at your service

>>> tn.write("quit\n")
>>> s = tn.read_very_eager()
>>> print s
221 2.0.0 closing connection r70si1582241yhm.54

>>>
$

These server response can then be parsed to determine what commands need to
be provided next.

Yet when I execute the same methods in a script, I am getting nothing in
response:

 $ cat script.py
#!/usr/bin/env python

import telnetlib

if __name__ == '__main__':
    print 'begin'
    tn = telnetlib.Telnet('gmail-smtp-in.l.google.com', 25)
    s = tn.read_very_eager()
    print s
    tn.write("helo\n")
    s = tn.read_very_eager()
    print s
    tn.write("quit\n")
    s = tn.read_very_eager()
    print s
    print 'end'
$ python script.py
begin



end
$

What do I need to do to emulate the IDE environment?  If I am needing to
capture stdout, it isn't readily apparent.

Any insight you can share would be greatly appreciated.

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110914/a466c68a/attachment.html>


More information about the Tutor mailing list