diff --git a/plugins/Http.py b/plugins/Http.py index 7027c5dcf..7f1b53e78 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -74,9 +74,12 @@ class Http(callbacks.Privmsg): if not url.startswith('http://'): irc.error('Only HTTP urls are valid.') return - fd = webutils.getUrlFd(url) - s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()]) - irc.reply(s) + try: + fd = webutils.getUrlFd(url) + s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()]) + irc.reply(s) + finally: + fd.close() _doctypeRe = re.compile(r'(]+>)', re.M) def doctype(self, irc, msg, args): @@ -385,11 +388,7 @@ class Http(callbacks.Privmsg): return url = 'http://zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&'\ 'tz=tz&ll=ll&zip=%s&Go=Go' % zipcode - try: - text = webutils.getUrl(url) - except webutils.WebError, e: - irc.error(str(e)) - return + text = webutils.getUrl(url) if 'daily usage limit' in text: irc.error('I have exceeded the site\'s daily usage limit.') return diff --git a/src/webutils.py b/src/webutils.py index 79d4cb722..9bc06e375 100644 --- a/src/webutils.py +++ b/src/webutils.py @@ -89,7 +89,7 @@ def getUrlFd(url): except socket.error, e: raise WebError, strError(e) except urllib2.URLError, e: - raise WebError, strError(e) + raise WebError, strError(e.reason[1]) except urllib2.HTTPError, e: raise WebError, strError(e)