title: Python telnet library issue, can't read the output without trap level set
body: <p>Don't know if the issue is with the python, the telnet library or the router but I just can't seem to get the script running like it should.</p>
  
  <p>It's a simple script that will display the output of the routing table from the router, but somehow if you don't set the command for trap/debug it won't display/print anything at all.</p>
  
  <p>I'm new to programming and just started to learn python, please tell me where I'm making a mistake or is it simply the routers limitation?</p>
  
  <p>The script is fairly simple: </p>
  
  <pre><code>import getpass
  import telnetlib
  import time
  
  user= "root" 
  password = "admin"
  
  print("Router Script")
  
  HOST = "192.168.100.1" #the gateway of the router
  
  tn = telnetlib.Telnet(HOST)
  
  tn.set_debuglevel(7) #the master of puppets 
  
  tn.read_until(b"Login:")
  time.sleep(1)
  tn.write(user.encode('ascii') + b"\n")
  
  tn.read_until(b"Password:")
  tn.write(password.encode('ascii') + b"\n")
  
  tn.read_until(b"WAP&gt;")
  tn.write(b"display ip route\n" )
  
  print(tn.read_all().decode('ascii'))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/UNnaX.png" rel="nofollow noreferrer">This is what the output looks like</a></p>
  
  <p>EDIT:
  I'm running it directly on my router using powershell i.e "py.exe C:\script.py" Also the script is written in python 3.0 if I need to mention, and the library is also for that.</p>
  
  <p>Here is the output as text as requested, it's all messy and without any order...</p>
  
  <pre><code>Router Script
  Telnet(192.168.100.1,23): recv b'\xff\xfb\x01\xff\xfb\x03\xff\xfb\x18\r\nWelcome Visiting Huawei Home Gateway\r\nC'
  Telnet(192.168.100.1,23): IAC WILL 1
  Telnet(192.168.100.1,23): IAC WILL 3
  Telnet(192.168.100.1,23): IAC WILL 24
  Telnet(192.168.100.1,23): recv b'opyright by Huawei Technologies Co., Ltd.\r\n\r\nLogin'
  Telnet(192.168.100.1,23): recv b':'
  Telnet(192.168.100.1,23): send b'root\n'
  Telnet(192.168.100.1,23): recv b'\xff\xfc\x01\xff\xfc\x03'
  Telnet(192.168.100.1,23): IAC WONT 1
  Telnet(192.168.100.1,23): IAC WONT 3
  Telnet(192.168.100.1,23): recv b'root\x07\r\nPassword:'
  Telnet(192.168.100.1,23): send b'admin\n'
  Telnet(192.168.100.1,23): recv b'\x07'
  Telnet(192.168.100.1,23): recv b'\r\nPassword is default value, please modify it!\r\nWA'
  Telnet(192.168.100.1,23): recv b'P&gt;'
  Telnet(192.168.100.1,23): send b'display ip route\n'
  Telnet(192.168.100.1,23): recv b'display ip route\x07'
  Telnet(192.168.100.1,23): recv b'\r\n\r\nFlags:[B]lackhole\r\n\r\n-------------------------'
  Telnet(192.168.100.1,23): recv b'--------------------------------------------------'
  Telnet(192.168.100.1,23): recv b'--------------------------------------------------'
  Telnet(192.168.100.1,23): recv b'---\r\nDest/MaskLen            Interface           G'
  Telnet(192.168.100.1,23): recv b'ateway             SourceIP            Flags      '
  Telnet(192.168.100.1,23): recv b' Metric      Origin              \r\n---------------'
  Telnet(192.168.100.1,23): recv b'--------------------------------------------------'
  Telnet(192.168.100.1,23): recv b'--------------------------------------------------'
  Telnet(192.168.100.1,23): recv b'-------------\r\n0.0.0.0/0               Internet   '
  Telnet(192.168.100.1,23): recv b'         --                  --                  -'
  Telnet(192.168.100.1,23): recv b'-          10          StaticRoute         \r\nxx.xx.'
  Telnet(192.168.100.1,23): recv b'xx.xx/14             VOIP                --         '
  Telnet(192.168.100.1,23): recv b'         xx.xx.xx.xx         --          0        '
  Telnet(192.168.100.1,23): recv b'   System              \r\nxx.xx.xx.xx/32          I'
  Telnet(192.168.100.1,23): recv b'nternet            --                  xx.xx.xx.'
  Telnet(192.168.100.1,23): recv b'xx      --          0           System           '
  Telnet(192.168.100.1,23): recv b'   \r\n192.168.100.0/24        LocalNetwork        -'
  Telnet(192.168.100.1,23): recv b'-                  192.168.100.1       --         '
  Telnet(192.168.100.1,23): recv b' 0           System              \r\n---------------'
  Telnet(192.168.100.1,23): recv b'--------------------------------------------------'
  Telnet(192.168.100.1,23): recv b'--------------------------------------------------'
  Telnet(192.168.100.1,23): recv b'-------------\r\nTotal: 4\r\n\r\nsuccess!\r\nWAP&gt;'
  </code></pre>