What am I doing wrong ?

Lee Cullip lcullip at techie.com
Fri Jul 26 05:58:06 EDT 2002


Hi all,
I'm really new to Python programming, only been tinkering with it a couple of days. I started writing this program and can't quite work out what I'm doing wrong. I want the user to enter the details in the dialog box and then when they hit execute it runs the telnet stuff and writes the output back to a file. I'm obviously doing something really stupid and need some help.
Any pointers would be great.

Cheers
Lee

My code :

import telnetlib
import sys
import Tkinter

from Tkinter import *

def detail() :
    telnet = telnetlib.Telnet(HOST)
    telnet.read_until("login: ")
    telnet.write(USER + "\n")
    telnet.read_until("Password: ")
    telnet.write(PASSWORD + "\n")
    telnet.write("ls -l /etc/init.d/oracle.sh\n")
    telnet.write("ls -l /etc/rc3.d|grep orac\n")
    telnet.write("cat /etc/oratab\n")
    telnet.write("exit\n")
    info = telnet.read_all()
    file = open('c:/temp/listing.txt', 'w')     #write info to file
    file.writelines(info)
    file.close()

login = Tk()

Label(login, text="User Name:").grid(row=0, sticky=W)
Label(login, text="Password:").grid(row=1, sticky=W)
Label(login, text="Host:").grid(row=2, sticky=W)

entry_ln = Entry(login)
entry_fn = Entry(login)
entry_ph = Entry(login)

USER = entry_ln.grid(row=0, column=1)
PASSWORD = entry_fn.grid(row=1, column=1)
HOST = entry_ph.grid(row=2, column=1)

b_execute = Button(login)
b_execute['text'] = "Execute"
b_execute['command'] = detail
b_execute.pack()
b_execute.grid(row=7, column = 1)
login.mainloop()

The errors I'm getting:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__
    return apply(self.func, args)
  File "C:\python scripts\teltest.py", line 9, in detail
    telnet.read_until("login: ")
  File "C:\Python22\lib\telnetlib.py", line 294, in read_until
    while not self.eof and apply(select.select, s_args) == s_reply:
  File "C:\Python22\lib\telnetlib.py", line 260, in fileno
    return self.sock.fileno()
AttributeError: 'NoneType' object has no attribute 'fileno'
Process terminated with exit code 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020726/9b70a472/attachment.html>


More information about the Python-list mailing list