Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: ProtocolError: (u'api.broadcasthe.net/', 524, 'Origin Time-out', <httplib.HTTPMessage instance at 0x65effda0>)

### INFO
**Python Version**: `2.7.9 (default, Sep 17 2016, 20:26:04) [GCC 4.9.2]`
**Operating System**: `Linux-4.9.35-v7+-armv7l-with-debian-8.0`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@f1c04d4bbeec508f8e8d59648f9c30858fa020a9
**Link to Log**: https://gist.github.com/447b35a960c9507d72e1fa46f021ee07
### ERROR
<pre>
2018-05-20 18:06:29 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [BTN] :: [f1c04d4] JSON-RPC protocol error while accessing provider. Error: ''
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/medusa/providers/torrent/json/btn.py#L246">medusa/providers/torrent/json/btn.py</a>", line 246, in _api_call
    int(offset)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L650">ext/jsonrpclib/jsonrpc.py</a>", line 650, in __call__
    return self.__send(self.__name, args)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L531">ext/jsonrpclib/jsonrpc.py</a>", line 531, in _request
    response = self._run_request(request)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L564">ext/jsonrpclib/jsonrpc.py</a>", line 564, in _run_request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1273, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L387">ext/jsonrpclib/jsonrpc.py</a>", line 387, in single_request
    response.msg)
ProtocolError: (u'api.broadcasthe.net/', 524, 'Origin Time-out', <httplib.HTTPMessage instance at 0x65effda0>)
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

[APP SUBMITTED]: ProtocolError: (u'api.broadcasthe.net/', 524, 'Origin Time-out', <httplib.HTTPMessage instance at 0x65effda0>)

### INFO
**Python Version**: `2.7.9 (default, Sep 17 2016, 20:26:04) [GCC 4.9.2]`
**Operating System**: `Linux-4.9.35-v7+-armv7l-with-debian-8.0`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@f1c04d4bbeec508f8e8d59648f9c30858fa020a9
**Link to Log**: https://gist.github.com/447b35a960c9507d72e1fa46f021ee07
### ERROR
<pre>
2018-05-20 18:06:29 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [BTN] :: [f1c04d4] JSON-RPC protocol error while accessing provider. Error: ''
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/medusa/providers/torrent/json/btn.py#L246">medusa/providers/torrent/json/btn.py</a>", line 246, in _api_call
    int(offset)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L650">ext/jsonrpclib/jsonrpc.py</a>", line 650, in __call__
    return self.__send(self.__name, args)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L531">ext/jsonrpclib/jsonrpc.py</a>", line 531, in _request
    response = self._run_request(request)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L564">ext/jsonrpclib/jsonrpc.py</a>", line 564, in _run_request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1273, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/home/pi/Medusa/<a href="../blob/f1c04d4bbeec508f8e8d59648f9c30858fa020a9/ext/jsonrpclib/jsonrpc.py#L387">ext/jsonrpclib/jsonrpc.py</a>", line 387, in single_request
    response.msg)
ProtocolError: (u'api.broadcasthe.net/', 524, 'Origin Time-out', <httplib.HTTPMessage instance at 0x65effda0>)
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

Resolving patch:
diff --git a/medusa/providers/torrent/json/btn.py b/medusa/providers/torrent/json/btn.py
--- a/medusa/providers/torrent/json/btn.py
+++ b/medusa/providers/torrent/json/btn.py
@@ -247,18 +247,20 @@ def _api_call(self, params=None, results_per_page=300, offset=0):
             )
             time.sleep(cpu_presets[app.CPU_PRESET])
         except jsonrpclib.jsonrpc.ProtocolError as error:
-            if error.message == (-32001, 'Invalid API Key'):
+            message = error.args[0]
+            if message == (-32001, 'Invalid API Key'):
                 log.warning('Incorrect authentication credentials.')
-            elif error.message == (-32002, 'Call Limit Exceeded'):
-                log.warning('You have exceeded the limit of'
-                            ' 150 calls per hour.')
+            elif message == (-32002, 'Call Limit Exceeded'):
+                log.warning('You have exceeded the limit of 150 calls per hour.')
+            elif isinstance(message, tuple) and message[1] in (524, ):
+                log.warning('Provider is currently unavailable. Error: {code} {text}',
+                            {'code': message[1], 'text': message[2]})
             else:
-                log.error('JSON-RPC protocol error while accessing provider.'
-                          ' Error: {msg!r}', {'msg': error.message})
+                log.error('JSON-RPC protocol error while accessing provider. Error: {msg!r}',
+                          {'msg': message})
 
-        except (socket.error, socket.timeout, ValueError) as error:
-            log.warning('Error while accessing provider.'
-                        ' Error: {msg}', {'msg': error})
+        except (socket.error, ValueError) as error:
+            log.warning('Error while accessing provider. Error: {msg!r}', {'msg': error})
         return parsed_json
 
 


Test patch: