fix netloc != hostname

This commit is contained in:
nemunaire 2014-12-16 00:45:01 +01:00
parent a1c086a807
commit dd285b67d1
2 changed files with 7 additions and 7 deletions

View File

@ -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 ("<tools.web> 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:

View File

@ -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: