title: Python http.client getaddrinfo failed
body: <p>I am using http.client to try to read an xml file from a host. I would use urllib2, but I get a BadStatusLine because there is 3 spaces before the xml header(I can not change that). That is why I am trying this route.</p>
  
  <p>I am stuck now and I keep getting an error (getaddrinfo failed).</p>
  
  <p>Below is my code and below that is the traceback. Can someone advise what I am doing wrong?</p>
  
  <p>FYI the address that works on the browser is <code>http://machineIP:81/command=AB&amp;time=2013-06-02</code></p>
  
  <p>I have no problem accessing the xml that way.</p>
  
  <p>Thanks for any help in advance!</p>
  
  <p>Code:</p>
  
  <pre><code>import http.client
  import datetime
  
  IP = input("Enter the IP: ")
  PT = str(81)
  F1 = datetime.date.today() - datetime.timedelta(days=2)
  
  print("Reading File...")
  html = http.client.HTTPConnection('http://' + IP  , port= PT)
  html.request("GET", '/command=AB&amp;time=' + str(F1))
  r1 = html.getresponse()
  
  print("Writing to file...")
  out = r1.read()
  f = open('Files/' + IP + '-' + str(F1) + '.xml', 'wb')
  print("Writing to file...")
  f.write(out)
  f.close()
  print("Done.")
  </code></pre>
  
  <p>Traceback:</p>
  
  <pre><code>C:\Users\Me\Desktop\Coding&gt;python file.py
  Enter the IP: *.***.***.***
  Reading File...
  Traceback (most recent call last):
    File "file.py", line 10, in &lt;module&gt;
      html.request("GET", '/command=AB&amp;time=' + str(F1))
    File "C:\Python33\lib\http\client.py", line 1049, in request
      self._send_request(method, url, body, headers)
    File "C:\Python33\lib\http\client.py", line 1087, in _send_request
      self.endheaders(body)
    File "C:\Python33\lib\http\client.py", line 1045, in endheaders
      self._send_output(message_body)
    File "C:\Python33\lib\http\client.py", line 890, in _send_output
      self.send(msg)
    File "C:\Python33\lib\http\client.py", line 828, in send
      self.connect()
    File "C:\Python33\lib\http\client.py", line 806, in connect
      self.timeout, self.source_address)
    File "C:\Python33\lib\socket.py", line 406, in create_connection
      for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  socket.gaierror: [Errno 11004] getaddrinfo failed
  </code></pre>