I have this very simple code to check if a site is up or down.
import httplib2
h = httplib2.Http()
response, content = h.request(\"http://www.folksdhhkjd.com\")
try:
response, content = h.request("http://www.folksdhhkjd.com")
if response.status==200:
print "Site is Up"
except httplib2.ServerNotFoundError:
print "Site is Down"
The issue with your code is that if the host doesn't respond, the request doesn't return ANY status code, and so the library throws an error (I think it's a peculiarity of the library itself, doing some sort of DNS resolution before trying to make the request).