Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: ConnectionError: HTTPConnectionPool(host='localhost', port=9091): Max retries exceeded with url: /transmission/rpc (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x6652ca10>: Failed to establish a new connection: [Errno 111] Connection refused',))
### 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.8`
**Commit**: pymedusa/Medusa@1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd
**Link to Log**: https://gist.github.com/c708dddd8cdddcf124cc4694b1ece4eb
### ERROR
<pre>
2017-09-06 02:22:52 ERROR    TORRENTCHECKER :: [1d0d7ea] Transmission: Unable to connect HTTPConnectionPool(host='localhost', port=9091): Max retries exceeded with url: /transmission/rpc (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x6652ca10>: Failed to establish a new connection: [Errno 111] Connection refused',))
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd/medusa/clients/torrent/generic.py#L79">medusa/clients/torrent/generic.py</a>", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "/home/pi/Medusa/<a href="../blob/1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd/lib/requests/sessions.py#L518">lib/requests/sessions.py</a>", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd/lib/requests/sessions.py#L475">lib/requests/sessions.py</a>", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/<a href="../blob/1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd/lib/requests/sessions.py#L585">lib/requests/sessions.py</a>", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd/lib/requests/adapters.py#L467">lib/requests/adapters.py</a>", line 467, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=9091): Max retries exceeded with url: /transmission/rpc (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x6652ca10>: Failed to establish a new connection: [Errno 111] Connection refused',))
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Discussion:
Dupplicate of https://github.com/pymedusa/Medusa/issues/3082

### 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**: [binsearch_search](../tree/binsearch_search)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a
**Link to Log**: https://gist.github.com/5b0ac2b1bd732bc24fd7d98e0171287e
### ERROR
<pre>
2017-12-14 00:15:11 ERROR    SNATCHQUEUE-MANUALSNATCH-161511 :: [40e7a64] Manual snatch failed!. For result: Shameless.US.S08E05.1080p.WEB.h264-CONVOY
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/medusa/search/queue.py#L487">medusa/search/queue.py</a>", line 487, in run
    self.success = snatch_episode(result)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/medusa/search/core.py#L157">medusa/search/core.py</a>", line 157, in snatch_episode
    result_downloaded = client.send_torrent(result)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/medusa/clients/torrent/generic.py#L239">medusa/clients/torrent/generic.py</a>", line 239, in send_torrent
    if not self._get_auth():
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/medusa/clients/torrent/transmission_client.py#L63">medusa/clients/torrent/transmission_client.py</a>", line 63, in _get_auth
    verify=app.TORRENT_VERIFY_CERT)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/ext/requests/sessions.py#L555">ext/requests/sessions.py</a>", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/medusa/session/core.py#L94">medusa/session/core.py</a>", line 94, in request
    **kwargs)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/ext/requests/sessions.py#L508">ext/requests/sessions.py</a>", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/ext/requests/sessions.py#L618">ext/requests/sessions.py</a>", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/40e7a64dfca33875ef1eefbe3f43f1d1b4d2583a/ext/requests/adapters.py#L508">ext/requests/adapters.py</a>", line 508, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=9091): Max retries exceeded with url: /transmission/rpc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x6470ccd0>: Failed to establish a new connection: [Errno 111] Connection refused',))
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### 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@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/3e6f0ea55fd48d88539f39aaae10c7b6
### ERROR
<pre>
2018-04-04 23:13:56 ERROR    TORRENTCHECKER :: [0da7d0a] Exception while checking torrent status.
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/medusa/torrent_checker.py#L43">medusa/torrent_checker.py</a>", line 43, in run
    client.remove_ratio_reached()
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/medusa/clients/torrent/transmission_client.py#L270">medusa/clients/torrent/transmission_client.py</a>", line 270, in remove_ratio_reached
    if not self._request(method='post', data=post_data):
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/medusa/clients/torrent/generic.py#L60">medusa/clients/torrent/generic.py</a>", line 60, in _request
    self._get_auth()
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/medusa/clients/torrent/transmission_client.py#L65">medusa/clients/torrent/transmission_client.py</a>", line 65, in _get_auth
    verify=app.TORRENT_VERIFY_CERT)
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/ext/requests/sessions.py#L555">ext/requests/sessions.py</a>", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/medusa/session/core.py#L99">medusa/session/core.py</a>", line 99, in request
    **kwargs)
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/ext/requests/sessions.py#L508">ext/requests/sessions.py</a>", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/ext/requests/sessions.py#L618">ext/requests/sessions.py</a>", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/0da7d0a5b457a7acf6686949361aa1a1c2fcf93d/ext/requests/adapters.py#L508">ext/requests/adapters.py</a>", line 508, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=9091): Max retries exceeded with url: /transmission/rpc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x64d02b30>: Failed to establish a new connection: [Errno 111] Connection refused',))
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### 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.11`
**Commit**: pymedusa/Medusa@824f29e849f3e407e1b59eee3b2a48fc29dfd5b5
**Link to Log**: https://gist.github.com/23d534f31cf302fd032ebfb3e9929a25
### ERROR
<pre>
2018-06-22 14:29:52 ERROR    SNATCHQUEUE-MANUALSNATCH-304219 :: [824f29e] Manual snatch failed!. For result: Marvels.Luke.Cage.S02.1080p.NF.WEB-DL.DDP5.1.x264-NTb
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/medusa/search/queue.py#L488">medusa/search/queue.py</a>", line 488, in run
    self.success = snatch_episode(result)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/medusa/search/core.py#L168">medusa/search/core.py</a>", line 168, in snatch_episode
    result_downloaded = client.send_torrent(result)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/medusa/clients/torrent/generic.py#L246">medusa/clients/torrent/generic.py</a>", line 246, in send_torrent
    if not self._get_auth():
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/medusa/clients/torrent/transmission_client.py#L65">medusa/clients/torrent/transmission_client.py</a>", line 65, in _get_auth
    verify=app.TORRENT_VERIFY_CERT)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/ext/requests/sessions.py#L555">ext/requests/sessions.py</a>", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/medusa/session/core.py#L102">medusa/session/core.py</a>", line 102, in request
    timeout=timeout, verify=ssl_cert, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/ext/requests/sessions.py#L508">ext/requests/sessions.py</a>", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/ext/requests/sessions.py#L618">ext/requests/sessions.py</a>", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/824f29e849f3e407e1b59eee3b2a48fc29dfd5b5/ext/requests/adapters.py#L508">ext/requests/adapters.py</a>", line 508, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=9091): Max retries exceeded with url: /transmission/rpc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x64e83bf0>: Failed to establish a new connection: [Errno 111] Connection refused',))
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Resolving patch:
diff --git a/medusa/clients/torrent/transmission_client.py b/medusa/clients/torrent/transmission_client.py
--- a/medusa/clients/torrent/transmission_client.py
+++ b/medusa/clients/torrent/transmission_client.py
@@ -23,6 +23,7 @@
 )
 from medusa.logger.adapters.style import BraceAdapter
 
+import requests.exceptions
 from requests.compat import urljoin
 
 
@@ -61,8 +62,18 @@ def _get_auth(self):
             'method': 'session-get',
         })
 
-        self.response = self.session.post(self.url, data=post_data.encode('utf-8'), timeout=120,
-                                          verify=app.TORRENT_VERIFY_CERT)
+        try:
+            self.response = self.session.post(self.url, data=post_data.encode('utf-8'), timeout=120,
+                                              verify=app.TORRENT_VERIFY_CERT)
+        except requests.exceptions.ConnectionError as error:
+            log.warning('{name}: Unable to connect. {error}',
+                        {'name': self.name, 'error': error})
+            return False
+        except requests.exceptions.Timeout as error:
+            log.warning('{name}: Connection timed out. {error}',
+                        {'name': self.name, 'error': error})
+            return False
+
         self.auth = re.search(r'X-Transmission-Session-Id:\s*(\w+)', self.response.text).group(1)
 
         self.session.headers.update({'x-transmission-session-id': self.auth})
diff --git a/medusa/search/queue.py b/medusa/search/queue.py
--- a/medusa/search/queue.py
+++ b/medusa/search/queue.py
@@ -495,7 +495,7 @@ def run(self):
 
         except Exception:
             self.success = False
-            log.exception('Manual snatch failed!. For result: {name}', {'name': result.name})
+            log.exception('Manual snatch failed! For result: {name}', {'name': result.name})
             ui.notifications.message('Error while snatching selected result',
                                      'Unable to snatch the result for <i>{name}</i>'.format(name=result.name))
 


Test patch: