From dd285b67d173ee8adfd0d1298dae9b643a354ebe Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 16 Dec 2014 00:45:01 +0100 Subject: [PATCH] fix netloc != hostname --- modules/networking/page.py | 6 +++--- tools/web.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/networking/page.py b/modules/networking/page.py index b1f3a56..0c0e24f 100644 --- a/modules/networking/page.py +++ b/modules/networking/page.py @@ -23,16 +23,16 @@ def headers(url): if o.netloc == "": raise IRCException("invalid URL") if o.scheme == "http": - conn = http.client.HTTPConnection(o.netloc, port=o.port, timeout=5) + conn = http.client.HTTPConnection(o.hostname, port=o.port, timeout=5) else: - conn = http.client.HTTPSConnection(o.netloc, port=o.port, timeout=5) + conn = http.client.HTTPSConnection(o.hostname, port=o.port, timeout=5) try: conn.request("HEAD", o.path, None, {"User-agent": "Nemubot v3"}) except socket.timeout: raise IRCException("request timeout") except socket.gaierror: print (" Unable to receive page %s from %s on %d." - % (o.path, o.netloc, o.port)) + % (o.path, o.hostname, o.port)) raise IRCException("an unexpected error occurs") try: diff --git a/tools/web.py b/tools/web.py index 6cc3c73..3265f34 100644 --- a/tools/web.py +++ b/tools/web.py @@ -43,7 +43,7 @@ def getScheme(url): def getHost(url): """Return the domain of a given URL""" - return urlparse(url).netloc + return urlparse(url).hostname def getPort(url): @@ -75,13 +75,13 @@ def getURLContent(url, timeout=15): o = urlparse("http://" + url) if o.scheme == "http": - conn = http.client.HTTPConnection(o.netloc, port=o.port, + conn = http.client.HTTPConnection(o.hostname, port=o.port, timeout=timeout) elif o.scheme == "https": - conn = http.client.HTTPSConnection(o.netloc, port=o.port, + conn = http.client.HTTPSConnection(o.hostname, port=o.port, timeout=timeout) elif o.scheme is None or o.scheme == "": - conn = http.client.HTTPConnection(o.netloc, port=80, timeout=timeout) + conn = http.client.HTTPConnection(o.hostname, port=80, timeout=timeout) else: return None try: