Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: AttributeError: 'NoneType' object has no attribute 'content'

### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.17134`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.11`
**Commit**: pymedusa/Medusa@f5973b28465246e67465d7d86bdc8aa74d13e659
**Link to Log**: https://gist.github.com/65cbbe28cae113abf840e4ccfacfb9b0
### ERROR
<pre>
2018-08-04 15:19:44 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [f5973b2] DailySearchQueueItem Exception, error: 'NoneType' object has no attribute 'content'
Traceback (most recent call last):
  File "C:\Medusa\Medusa\<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/search/queue.py#L289">medusa\search\queue.py</a>", line 289, in run
    self.success = snatch_episode(result)
  File "C:\Medusa\Medusa\<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/search/core.py#L135">medusa\search\core.py</a>", line 135, in snatch_episode
    nzb_data = result.provider.download_nzb_for_post(result)
  File "C:\Medusa\Medusa\<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/providers/nzb/binsearch.py#L267">medusa\providers\nzb\binsearch.py</a>", line 267, in download_nzb_for_post
    verify=verify, hooks={}, allow_redirects=True).content
AttributeError: 'NoneType' object has no attribute 'content'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

Resolving patch:
diff --git a/medusa/providers/nzb/binsearch.py b/medusa/providers/nzb/binsearch.py
--- a/medusa/providers/nzb/binsearch.py
+++ b/medusa/providers/nzb/binsearch.py
@@ -42,7 +42,7 @@ def __init__(self):
         self.url = 'https://www.binsearch.info'
         self.urls = {
             'search': urljoin(self.url, 'index.php'),
-            'rss': urljoin(self.url, 'browse.php')
+            'rss': urljoin(self.url, 'browse.php'),
         }
 
         # Proper Strings
@@ -86,8 +86,9 @@ def search(self, search_strings, **kwargs):
                             'max': 50,
                         }
                         search_url = self.urls['rss']
+
                     response = self.session.get(search_url, params=search_params)
-                    if not response:
+                    if not response or not response.text:
                         log.debug('No data returned from provider')
                         continue
 
@@ -139,10 +140,11 @@ def process_column_header(td):
                     title = self.clean_title(col['subject'].text, mode)
 
                 except AttributeError:
-                    log.debug('Parsing rows, that may not always have usefull info. Skipping to next.')
+                    log.debug('Parsing rows, that may not always have useful info. Skipping to next.')
                     continue
                 if not all([title, nzb_id]):
                     continue
+
                 # Obtain the size from the 'description'
                 size_field = BinSearchProvider.size_regex.search(col['subject'].text)
                 if size_field:
@@ -227,7 +229,7 @@ def download_result(self, result):
 
         data = {
             data.split('=')[1]: 'on',
-            'action': 'nzb'
+            'action': 'nzb',
         }
 
         if download_file(url, filename, method='POST', data=data, session=self.session,
@@ -255,7 +257,7 @@ def download_nzb_for_post(self, result):
 
         data = {
             data.split('=')[1]: 'on',
-            'action': 'nzb'
+            'action': 'nzb',
         }
 
         log.info('Downloading {result} from {provider} at {url} and data {data}',
@@ -263,15 +265,18 @@ def download_nzb_for_post(self, result):
 
         verify = False if self.public else None
 
-        result = self.session.post(url, data=data, headers=self.session.headers,
-                                   verify=verify, hooks={}, allow_redirects=True).content
+        response = self.session.post(url, data=data, headers=self.session.headers,
+                                     verify=verify, hooks={}, allow_redirects=True)
+        if not response or not response.content:
+            log.warning('Failed to download the NZB from BinSearch')
+            return None
 
         # Validate that the result has the content of a valid nzb.
-        if not BinSearchProvider.nzb_check_segment.search(result):
-            log.info('Result returned from BinSearch was not a valid nzb')
+        if not BinSearchProvider.nzb_check_segment.search(response.content):
+            log.warning('Result returned from BinSearch was not a valid NZB')
             return None
 
-        return result
+        return response.content
 
     def _get_size(self, item):
         """


Test patch: