Python telnetlib try / catch问题

时间:2016-11-17 05:06:54

标签: python try-catch telnetlib

有人可以帮我解决下面的代码吗? 使用下面的代码进行telnet连接。 为什么在try语句之后仍然会执行异常?即使超时数量增加,对话框仍然显示。

try:
    tn = telnetlib.Telnet('1.1.1.1', port=23, timeout=3)
    tn.set_debuglevel(2)
    idx, obj, response = tn.expect(["$ ","# "],1)
    tn.write(str(all_cmd))
    print(tn.read_very_eager())
    tn.write('exit\r')
    time.sleep(0.05)
    tn.read_all()
except IOError:
    dlg = wx.MessageDialog(self, 'Unable to connect to telnet server!','Error!',wx.OK | wx.ICON_ERROR)
    dlg.ShowModal()
    dlg.Destroy()

0 个答案:

没有答案