From 9ae126ce263763d80095ff33b06ebd87935af81a Mon Sep 17 00:00:00 2001 From: Deimos Date: Sun, 30 Sep 2018 23:48:23 -0600 Subject: [PATCH] Improve exception-handling in site icon downloader Handles some more errors that came up in practice when I applied this to the production data. --- tildes/consumers/site_icon_downloader.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tildes/consumers/site_icon_downloader.py b/tildes/consumers/site_icon_downloader.py index bbf0eae..696af6a 100644 --- a/tildes/consumers/site_icon_downloader.py +++ b/tildes/consumers/site_icon_downloader.py @@ -59,7 +59,7 @@ class SiteIconDownloader(PgsqlQueueConsumer): try: response = requests.get(favicon_url, timeout=5) - except requests.exeptions.Timeout: + except requests.exceptions.RequestException: return if response.status_code != 200: @@ -72,7 +72,10 @@ class SiteIconDownloader(PgsqlQueueConsumer): @staticmethod def _get_icon_from_response(response: requests.Response) -> Optional[Image.Image]: """Return a properly-sized icon Image extracted from a Response.""" - favicon = Image.open(BytesIO(response.content)) + try: + favicon = Image.open(BytesIO(response.content)) + except (OSError, ValueError): + return None if favicon.format == "ICO": # get the 32x32 size if it's present, otherwise resize the largest one