title: Python Telnetlib - Enters password before password input asked
body: <p>I am new to python.I am trying to connect to telnet,then login using the username and password and execute command and grep the results one by one.I have coded as below :</p>
  
  <pre><code>print ("Starting Client...")
  host    = "&lt;myIp&gt;"
  timeout = 120
  user = "myUserName"
  password = "myPassword"
  
  print ("Connecting...")
  try:
      session = telnetlib.Telnet(host, 23, timeout)
      session.read_until("USERNAME : ",2)
      session.write(user + "\n")
      print("UserName entered")
      response = session.read_until("PASSWORD : ",2)
      print(str(response))
      session.write(password + "\n")
      print("password Entered")
  except Exception,e:
      print ("socket timeout")
  else:
      print("Sending Commands...")
      session.write("Mycommand".encode('ascii') + b"\r")
      print("Reading...")
      output = session.read_until("commandBash&gt;", timeout )
      session.close()
      print(output)
      print("Done")
  </code></pre>
  
  <p>For the above program i get my output as :</p>
  
  <pre><code>Starting Client...
  Connecting...
  UserName entered
   myUserName
  password Entered
  Sending Commands...
  Reading...
  myPasswordMycommand
  
  PASSWORD:
  Done
  </code></pre>
  
  <p>From this i could know that password hasnt been even entered when it asks for password.It actually enters password and command before password is prompted.So i even tried putting time.sleep(20) after username entered.Still no use.I couldnt figure out what i am missing here.Please help me out friends</p>