From f2affda37e27007b921f5891737fbc8662552a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Wed, 3 Jan 2018 04:24:18 +0100 Subject: [PATCH] IrcMiRCARTBot.py:IrcMiRCARTBot._dispatchPrivmsg(): catch urllib.error.HTTPError exception during download. IrcMiRCARTBot.py:IrcMiRCARTBot._dispatchPrivmsg(): fix typo. --- IrcMiRCARTBot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/IrcMiRCARTBot.py b/IrcMiRCARTBot.py index d00fc24..3be31c9 100755 --- a/IrcMiRCARTBot.py +++ b/IrcMiRCARTBot.py @@ -117,7 +117,12 @@ class IrcMiRCARTBot(IrcClient.IrcClient): os.remove(asciiTmpFilePath) if os.path.isfile(imgTmpFilePath): os.remove(imgTmpFilePath) - urllib.request.urlretrieve(asciiUrl, asciiTmpFilePath) + try: + urllib.request.urlretrieve(asciiUrl, asciiTmpFilePath) + except urllib.error.HTTPError as err: + self._log("Download failed with HTTP status code {}".format(err.code)) + self.queue("PRIVMSG", message[2], "4/!\\ Download failed with HTTP status code {}!".format(err.code)) + return _MiRCART = MiRCART.MiRCART(asciiTmpFilePath, imgTmpFilePath, "DejaVuSansMono.ttf", 11) imgurResponse = self._uploadToImgur(imgTmpFilePath, "MiRCART image", "MiRCART image", "c9a6efb3d7932fd") if imgurResponse[0] == 200: @@ -125,7 +130,7 @@ class IrcMiRCARTBot(IrcClient.IrcClient): self.queue("PRIVMSG", message[2], "8/!\\ Uploaded as: {}".format(imgurResponse[1])) else: self._log("Upload failed with HTTP status code {}".format(imgurResponse[0])) - self.queue("PRIVMSG", message[2], "4/!\\ Uploaded failed with HTTP status code {}!".format(imgurResponse[0])) + self.queue("PRIVMSG", message[2], "4/!\\ Upload failed with HTTP status code {}!".format(imgurResponse[0])) if os.path.isfile(asciiTmpFilePath): os.remove(asciiTmpFilePath) if os.path.isfile(imgTmpFilePath):