From a3d1c7ea639bd6cbcbf775b4ae2e234645234474 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Sat, 1 Oct 2016 13:12:17 -0500 Subject: [PATCH] Added an error check for an issue where e621 provides data that is not json encodable --- cogs/links.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cogs/links.py b/cogs/links.py index 4a5f924..fa0a2dd 100644 --- a/cogs/links.py +++ b/cogs/links.py @@ -7,6 +7,7 @@ import aiohttp import random import re import math +import json class Links: @@ -142,9 +143,12 @@ class Links: url += "%20rating:explicit" else: url += "%20rating:safe" - - async with self.session.get(url, headers=self.headers) as r: - data = await r.json() + try: + async with self.session.get(url, headers=self.headers) as r: + data = await r.json() + except json.JSONDecodeError: + await self.bot.say("Sorry, I had trouble connecting at the moment; please try again later") + return # Try to find an image from the list. If there were no results, we're going to attempt to find # A number between (0,-1) and receive an error.