read_until problem under telnetlib

Daniel Fackrell newsgroups.NOSPAM at dfackrell.mailshell.com
Wed Jun 11 15:19:41 EDT 2003


dma2 wrote:
> 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

You are using tn.read_until() where you're getting the traceback, and
tn.expect() where you're not.  I suspect you intended tn.expect() in both
places, as read_until() takes a string-like object (Maybe "character buffer"
in the error could be replaced with something clearer?) as its first
argument instead of a list of regular expressions.

See: http://www.python.org/doc/current/lib/telnet-objects.html

--
Daniel Fackrell (newsgroups.NOSPAM at dfackrell.mailshell.com)
When we attempt the impossible, we can experience true growth.






More information about the Python-list mailing list