From bac30e814342e83933964e27c2875c0b8ae30c6a Mon Sep 17 00:00:00 2001
From: miigotu <miigotu@gmail.com>
Date: Tue, 8 Dec 2015 03:07:55 -0800
Subject: [PATCH] make sure find returned something before calling other method
 with bs4 in tvchaos Fixes
 https://github.com/SickRage/sickrage-issues/issues/174

---
 sickbeard/providers/tvchaosuk.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sickbeard/providers/tvchaosuk.py b/sickbeard/providers/tvchaosuk.py
index 3b265b3dc..7542bb2c6 100644
--- a/sickbeard/providers/tvchaosuk.py
+++ b/sickbeard/providers/tvchaosuk.py
@@ -142,8 +142,14 @@ class TVChaosUKProvider(TorrentProvider):
                     continue
 
                 with BS4Parser(data) as html:
-                    torrent_table = html.find(id='listtorrents').find_all('tr')
-                    for torrent in torrent_table:
+                    torrent_table = html.find(id='listtorrents')
+                    if not torrent_table:
+                        logger.log(u"Data returned from provider does not contain any torrents", logger.DEBUG)
+                        continue
+
+                    torrent_rows = torrent_table.find_all('tr')
+
+                    for torrent in torrent_rows:
                         try:
                             freeleech = torrent.find('img', alt=re.compile('Free Torrent'))
                             if self.freeleech and not freeleech:
-- 
GitLab