From 30053c2cfe18b77da52df38daebbc91b3a2b5240 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sun, 12 May 2013 06:01:36 +0200 Subject: [PATCH] Handle mangafox download errors slightly nicer. --- manga/mangafox.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/manga/mangafox.py b/manga/mangafox.py index ed40efb..b165d21 100644 --- a/manga/mangafox.py +++ b/manga/mangafox.py @@ -6,8 +6,16 @@ soup = BeautifulSoup.BeautifulSoup class imgstream(lib.imgstream): def __init__(self, url): self.bk = urllib.urlopen(url) - self.ctype = self.bk.info()["Content-Type"] - self.clen = int(self.bk.info()["Content-Length"]) + ok = False + try: + if self.bk.getcode() != 200: + raise IOError("Server error: " + str(self.bk.getcode())) + self.ctype = self.bk.info()["Content-Type"] + self.clen = int(self.bk.info()["Content-Length"]) + ok = True + finally: + if not ok: + self.bk.close() def fileno(self): return self.bk.fileno() -- 2.11.0