improved down

This commit is contained in:
Ryan Hitchman 2009-07-10 00:06:55 -06:00
parent 5bd945b7c1
commit 5d4c321169
1 changed files with 7 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import urllib2
import urlparse
from util import hook
@ -13,12 +14,14 @@ def down(inp):
if 'http://' not in inp:
inp = 'http://' + inp
inp = 'http://' + urlparse.urlparse(inp).netloc
# http://mail.python.org/pipermail/python-list/2006-December/589854.html
try:
request = urllib2.Request(inp)
request.get_method = lambda: "HEAD"
http_file = urllib2.urlopen(request, timeout=10)
head = http_file.headers
return 'it seems to be up'
http_file = urllib2.urlopen(request)
head = http_file.read()
return inp + ' seems to be up'
except urllib2.URLError:
return 'it seems to be down'
return inp + ' seems to be down'