Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96489 > unrolled thread
| Started by | manjunatha.mahalingappa@gmail.com |
|---|---|
| First post | 2015-09-13 00:38 -0700 |
| Last post | 2015-09-13 12:40 -0400 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
How to use the returned telnet object after creating the telnet session. manjunatha.mahalingappa@gmail.com - 2015-09-13 00:38 -0700
Re: How to use the returned telnet object after creating the telnet session. Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-13 10:34 +0000
Re: How to use the returned telnet object after creating the telnet session. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-13 12:40 -0400
| From | manjunatha.mahalingappa@gmail.com |
|---|---|
| Date | 2015-09-13 00:38 -0700 |
| Subject | How to use the returned telnet object after creating the telnet session. |
| Message-ID | <e578698e-7721-4c01-a270-61fa211c3f79@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-09-13 10:34 +0000 |
| Message-ID | <mt3jg9$vvf$1@dont-email.me> |
| In reply to | #96489 |
On Sun, 13 Sep 2015 00:38:03 -0700, manjunatha.mahalingappa wrote: > 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'". My best guess would be that something failed and has returned None instead of the object / class you're expecting. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2015-09-13 12:40 -0400 |
| Message-ID | <mailman.483.1442162427.8327.python-list@python.org> |
| In reply to | #96489 |
On Sun, 13 Sep 2015 00:38:03 -0700 (PDT), manjunatha.mahalingappa@gmail.com
declaimed the following:
> connection.write(cmd + "\n")
>
Here you added a termination newline.
>
>#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)
>
Indentation wrong?
> T1.write("show config") <<<<<<<<<ERROR PART
No new line here...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web