[Tutor] telnet read_until problems

Chris Hallman challman at gmail.com
Mon Feb 12 21:00:49 CET 2007


I've written a program that tests ISDN dial backup at 1,000 locations. I've
broken up the logic into server functions within a threading class (i.e.
logon, get interfaces, get dial string, etc.). At 999 locations, the
following code extract the first of three dial strings:

    def GetDialString(self):
        """ This function extracts the dial string."""
        self.tn.write("term len 0\n")
        self.tn.expect([self.host.upper() + "#"], 7)
        self.tn.write("sh dialer | i Default\n")
        self.data = self.tn.read_until(self.host.upper() + "#", 7)
        print self.data
        match = re.search("\d\d\d\d\d\d\d\d\d\d\d+", self.data)
        if match is not None:
            rc = match.group()
        else:
            rc = "missing"
        return rc

One location doesn't return it's dial string. In Idle, the output is:

>>> print data
sh dialer | i Default
17002111000              1          0    8w2d           successful   Default
17002111002              0          0    never                   -   Default
17002111001              1          0    never                   -   Default
J07MR3640#

The "print data" statement yields:

term len 0
J07MR3640#

I've run a packet capture and I see the data coming back every time. I don't
understand why it works fine for 999 out of 1,000 locations. Any
suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070212/b03049d6/attachment.html 


More information about the Tutor mailing list