2

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()
Ébe Isaac
  • 11,563
  • 17
  • 64
  • 97
  • What error are you getting? Can you change your except block to be `except IOError as e` and then add a line right after that saying `print(e)` so we can see what's going wrong? – Christopher Shroba Nov 17 '16 at 05:16
  • you may have exception different than `IOError`. Always show full error message in question. – furas Nov 17 '16 at 05:25
  • the error i get in IOError is "socket timeout".even if i will increase the timeout=10,the exception dlg still displayed :( – user3584454 Nov 17 '16 at 06:45

0 Answers0