title: telnetlib script working on Windows 7 Prof but not on Windows server 2012 R2
body: <p>Hi I'm running the following telnet script from python as well as from powershell. 
  In python I'm using telnetlib and running the following:</p>
  
  <pre><code>import telnetlib
  
  HOST = "hostname"
  PORT = 25
  TIMEOUT = 5
  
  
  def test_telnet(Host, Port, Timeout):
      tn = telnetlib.Telnet(host=Host, port=Port, timeout=Timeout)
      print 'Client Connecton Made.'
      tn.write("HELO &lt;domainName&gt;\r\n")
      tn.write("Mail From: senderemail@domain.com\r\n")
      tn.write("RCPT TO: rcpt@gmail.com\r\n")
      tn.write("DATA\r\n")
      tn.write("Subject: Some Subject.\r\n")
      tn.write("First Line of Body\r\n")
      tn.write("\r\n")
      tn.write("Thanks\r\n")
      tn.write("\r\n")
      tn.write("Name\r\n")
      tn.write(".\r\n")
      tn.write("exit\r\n")
      print tn.read_all()
      print 'Client Connection Lost.'
  
  test_telnet(HOST, PORT, TIMEOUT)
  </code></pre>
  
  <p>This script is working in Windows 7 but not in Windows Server 2012 R2. Both even gave me the same time out error; however it still is successful when executed from windows 7 machine. The error goes like:</p>
  
  <pre><code>C:\Anaconda\python.exe C:/telnetTest.py
  Client Connecton Made.
  Traceback (most recent call last):
    File "C:/telnetTest.py", line 34, in &lt;module&gt;
      test_telnet(HOST, PORT, TIMEOUT)
    File "C:/telnetTest.py", line 31, in test_telnet
      print tn.read_all()
    File "C:\Anaconda\lib\telnetlib.py", line 384, in read_all
      self.fill_rawq()
    File "C:\Anaconda\lib\telnetlib.py", line 575, in fill_rawq
      buf = self.sock.recv(50)
  socket.timeout: timed out
  
      Process finished with exit code 1
  </code></pre>
  
  <p>I even run the line-by-line version of this script and it works on both the machines. The line-by-line commands used in powershell are as follows:</p>
  
  <pre><code>Telnet &lt;hostname&gt; 25
  Helo domainName
  Mail From: senderemail@domain.com
  RCPT TO: rcpt@gmail.com
  DATA
  Subject: Some Subject. 
  First Line of Body
  
  Thanks
  
  Name
  .
  quit
  </code></pre>
  
  <p>The powershell version, pycharm version, python version (anaconda 2.7.8) are the same in both machines. </p>
  
  <p>I even tried encoding as mentioned in this post: <a href="https://stackoverflow.com/questions/10952514/telnetlib-python-example">telnetlib python example</a>
  But it wasn't the issue. 
  I'm curious to know why it is not running using telnetlib even when it's running in powershell.</p>
  
  <p>Thanks.</p>