1

I need to make a simple header request to every URL in a large set, to check if they are still available. Now I made the following code:

from http import client
for i, triple in enumerate(catalouge):
    connection = client.HTTPConnection(triple[2].strip('http://'))
    connection.request('HEAD', '/')
    print(connection.getresponse().status + ' on entry ' + str(i+1))

Now catalouge is a set of all the links with the 3rd element being the URL which needs to be checked. The .strip('http://') part is needed since I will receive this error otherwise:

http.client.InvalidURL: nonnumeric port:

With this code in place I now receive this error:

Traceback (most recent call last):
  [...]
    connection.request('HEAD', '/')
  File "/usr/lib/python3.4/http/client.py", line 1137, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1182, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1133, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 963, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 898, in send
    self.connect()
  File "/usr/lib/python3.4/http/client.py", line 871, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 494, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.4/socket.py", line 533, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

Did I miss something? Any suggestion would be very appreciated.

R.P.O.D.
  • 81
  • 1
  • 5
  • 1
    I think it is likely that you have a problem when using string.strip(…), because `'http://test.com'.strip('http://')` yields `'est.com'` for me. – Jakob Runge Mar 21 '16 at 15:41

0 Answers0