Can someone help me how to fix the code below? Been using the code below for telnet connection. Why is it that the exception will still be executed after try statement? Dialog still displayed, even if timeout number increases.
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()