From 885b765888096f7c8e5a53f54280a9fdfb28f688 Mon Sep 17 00:00:00 2001 From: KaneTW Date: Wed, 3 Dec 2014 20:10:28 +0100 Subject: [PATCH] down.py URL bugfix and detailed error messages Adjusts urlparse behaviour for schemeless URLs (see python docs) to put the domain name into netloc, and makes error messages more detailed so differentiation between a HTTP error or DNS error can occur. --- plugins/down.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/down.py b/plugins/down.py index 7044095..776401c 100644 --- a/plugins/down.py +++ b/plugins/down.py @@ -7,6 +7,10 @@ from util import hook, http def down(inp): '''.down -- checks to see if the website is down''' + # urlparse follows RFC closely, so we have to check for schema existance and prepend empty schema if necessary + if not inp.startswith('//') and '://' not in inp: + inp = '//' + inp + urlp = urlparse.urlparse(inp, 'http') if urlp.scheme not in ('http', 'https'): @@ -18,5 +22,5 @@ def down(inp): try: http.get(inp, get_method='HEAD') return inp + ' seems to be up' - except http.URLError: - return inp + ' seems to be down' + except http.URLError as error: + return inp + ' seems to be down. Error: %s' % error.reason