read_until problem under telnetlib

dma2 david_martin at carrefour.com
Wed Jun 11 12:47:29 EDT 2003


hi, i am having a problem that seems not to have been adressed yet on
this list

i work on thousands of cisco equipements, and as usual the cisco
prompt is not consistent across their whole range of equipements and i
need this kind of code

tn.write ('sh conf\n') #this command print the startup configuration
on cisco
try:
   sh_conf = tn.read_until(["\(enable\)", "#"],5)
except EOFError :
   print "telnet interrompu, impossible de lire le sh_conf" + ip
   unreachable.write("telnet interrompu, impossible de lire le
sh_conf" + ip + '\n')
   continue
   
i used to match a sting like "foo" i had previously sent to the
equipement but i need a cleaner solution that does not make the cisco
complain about unknown command
i want to match 2 differents strings ( ios or catos )  
 
and i get this message

Traceback (most recent call last):
  File "C:\Python22\script\telnet-python-2.py", line 265, in ?
    sh_ver = tn.read_until([ "\(enable\)", "#" ],2)
  File "C:\Python22\lib\telnetlib.py", line 284, in read_until
    i = self.cookedq.find(match)
TypeError: expected a character buffer object

i use this line elsewhere and it works

prompt5 = tn.expect (["\(enable\)","#"],2)

expect is supposed to accept multiple string or compile regexp
but i can't get it to work
any help welcome
thanks




More information about the Python-list mailing list