0

以下のコードのように、telnet セッションを使用する必要があります。

class ModTelnet(MXComm):
def __init__(self):
    MXComm.__init__(self)

def _connect(self):
    #connect to telnet session @ localhost port 4444
    try:
        HOST = "localhost"
        port = "4444"
     #   tn = telnetlib.Telnet(HOST, port)
        tn.open(HOST, port)
    except:
        print "Connection refused"


def _receive(self):
    #receive data (= msg) from telnet stdout
    try:
        data = tn.read_all()
        return data
    except tn.eof.ERR as ex:
        if 'timeout error' not in ex.args[0]:
            print 'Connection error:', ex 
            raise Disconnected()

def _send(self, data):
    #send command to telnet session
    try:          
        tn.write(data + "\n")
    except tn.socket.error as ex:
        if 'timeout error' not in ex.args[0]:
            print 'Connection error:', ex 
            raise Disconnected()

発生したエラーは次のとおりです。

QApplication: Invalid Display* argument
Connection refused
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
    self.run()
  File "/home/mk3/MODiMX27/PELM_Gui/src/modimx.py", line 188, in run
    self._conn.try_get_data()
  File "/home/mk3/MODiMX27/PELM_Gui/src/modimx.py", line 58, in try_get_data
    rx_item = self._receive()
  File "/home/mk3/MODiMX27/PELM_Gui/src/modimx.py", line 112, in _receive
    except tn.eof.ERR as ex:

NameError: global name 'tn' is not defined

問題は、最初のメソッド「接続」で開いている telnet セッションを認識しないように見えることです...どうすればこれを最善の方法で行うことができますか?

4

1 に答える 1

2

tnself.tn他のメソッドがアクセスできるようにする必要があります

于 2011-04-30T19:08:21.740 に答える