mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Handled the ugly "timed out" error message.
This commit is contained in:
parent
4db8dfb773
commit
cbb015a56e
@ -42,18 +42,24 @@ class WebError(Exception):
|
||||
|
||||
urlRe = re.compile(r"(\w+://[^\])>\s]+)", re.I)
|
||||
|
||||
REFUSED = 'Connection refused.'
|
||||
TIMED_OUT = 'Connection timed out.'
|
||||
RESET_BY_PEER = 'Connection reset by peer.'
|
||||
|
||||
def getUrlFd(url):
|
||||
"""Gets a file-like object for a url."""
|
||||
try:
|
||||
fd = urllib2.urlopen(url)
|
||||
return fd
|
||||
except socket.timeout, e:
|
||||
raise WebError, TIMED_OUT
|
||||
except socket.error, e:
|
||||
if e.args[0] == 111:
|
||||
raise WebError, 'Connection refused.'
|
||||
raise WebError, REFUSED
|
||||
elif e.args[0] in (110, 10060):
|
||||
raise WebError, 'Connection timed out.'
|
||||
raise WebError, TIMED_OUT
|
||||
elif e.args[0] == 104:
|
||||
raise WebError, 'Connection reset by peer.'
|
||||
raise WebError, RESET_BY_PEER
|
||||
else:
|
||||
raise WebError, str(e)
|
||||
except (urllib2.HTTPError, urllib2.URLError), e:
|
||||
|
Loading…
Reference in New Issue
Block a user