From 8a769bbe18780ee63d754eb92c0b75ca42cead62 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 1 Jun 2019 23:42:00 +0300 Subject: [PATCH] Fix possible feed reading errors --- rss/bot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rss/bot.py b/rss/bot.py index 892c147..be2e2d3 100644 --- a/rss/bot.py +++ b/rss/bot.py @@ -118,9 +118,16 @@ class RSSBot(Plugin): async def read_feed(self, url: str) -> str: try: resp = await self.http.get(url) - except aiohttp.client_exceptions.ClientError: + except Exception: + self.log.exception(f"Error fetching {url}") return "" - content = await resp.text() + try: + content = await resp.text() + except UnicodeDecodeError: + try: + content = await resp.text(encoding="utf-8") + except: + content = str(await resp.read())[2:-1] return content @staticmethod