Hello all,

First I would like thank you for creating such good platform for discussing 
python..!!!

Assume that I will pass IP and port information from a function to open the 
telnet session. have opened the telnet session and after opening the telnet 
session I returned telnet object to calling function.

Now in the calling function If I use that object to read or write to terminal 
I'm getting ERROR "AttributeError: 'NoneType' object has no attribute 
'read_very_eager'".


#Open telnet connection to devices

def open_telnet_conn(dname,ip,port):

try:
        TELNET_PORT = port
        TELNET_TIMEOUT = 5
        READ_TIMEOUT = 5
        cmd = "show config"
        #Logging into device

        connection=telnetlib.Telnet(ip, TELNET_PORT, TELNET_TIMEOUT)

        time.sleep(1)
        connection.write(cmd + "\n")

        #Here I'm able to write to connection object..
        connection.write("\n")
        time.sleep(2)

        router_output = connection.read_very_eager()
        print router_output

        return(connection)

except IOError:

        print "Input parameter error! Please check username, password and file 
name."


#Function to read device IP and port . and this info for opening the telnet 
session.
def IP_port(file):
T = []
F = open(file,'r')
F.seek(0)

line=F.read()
tuples = re.findall(r'(.+?)\s+(.+?)\s+(\d+)',line)

#(dname,IP,port)= tuples

for (dname,ip,port) in tuples:
        T1=open_telnet_conn(dname,ip,port)
        #HERE I will get the telnet object point to the same location as the 
connection object. But I'm unable to write or read anything here. I think need 
to convert the object T1 to TELNET CLASS object type..

        print T1
        T1.write("show config") <<<<<<<<<ERROR PART

        router_output = T1.read_very_eager()
        print router_output
        T.append(T1)
        return(T)


# import the LC/RSP name ,port and IP address
file='/users/manmahal/MANJU/IP_port.txt'
list_of_telnet=IP_port(file)



NOTE: the content of the file is as below:

RSP1 172.27.40.60 2002

RSP0 172.27.40.60 2001

LC0 172.27.40.60 2010


Idea is to create the telnet sessions store them in list or dictionary use them 
as and when needed.
Any thought or solution is welcome...!!!



Regards
Manju
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to