title: (Python) socket.gaierror: [Errno 11001] getaddrinfo failed
body: <p>I'm not sure whats wrong with this code I keep getting that socket.gaierror error ;\ .</p>
  
  <pre><code>import sys
  import socket
  import random
  
  filename = "whoiservers.txt"
  
  server_name = random.choice(list(open(filename)))
  
  print "connecting to %s..." % server_name
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((server_name, 43))
  s.send(sys.argv[1] + "\r\n")
  response = ''
  while True:
      d = s.recv(4096)
      response += d
      if d == '':
          break
  s.close()
  print
  print response
  
  
      s.connect((server_name, 43))
    File "&lt;string&gt;", line 1, in connect
  socket.gaierror: [Errno 11001] getaddrinfo failed
  </code></pre>
  
  <h3>Update:</h3>
  
  <p>After adding <code>server_name = random.choice(list(open(filename)))[:-1]</code> I dont get that socket.gaierror anymore but I get:</p>
  
  <blockquote>
    <p>socket.error: [Errno 10060] A connection attempt failed because the connected pa
    rty did not properly respond after a period of time, or established connection f
    ailed because connected host has failed to respond</p>
  </blockquote>