# Buggy code
def _get_auth(self):
    post_data = json.dumps(
        {
            "method": "session-get",
        }
    )

    self.response = self.session.post(
        self.url,
        data=post_data.encode("utf-8"),
        timeout=120,
        verify=app.TORRENT_VERIFY_CERT,
    )
    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})

    # Validating Transmission authorization
    post_data = json.dumps(
        {
            "arguments": {},
            "method": "session-get",
        }
    )

    self._request(method="post", data=post_data)

    return self.auth


# Traceback (ConnectionError)
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Loading show info from TVDBv2
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Using language from show settings: en
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Configured language en override show language of en
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Getting all series data for 301236
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Getting all show data for 301236
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: https://api.thetvdb.com/series/301236 [Status: 200]
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Getting all episodes of 301236
2017-09-06 02:22:50 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] GET URL: http://forum.tntvillage.scambioetico.org/?filter=CBC+Marketplace+S44E08Marketplace+CA+S44E08Marketplace+S44E08&act=allreleases [Status: 200]
2017-09-06 02:22:50 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20130405 Firefox/22.0
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: https://api.thetvdb.com/series/301236/episodes/query?page=1 [Status: 200]
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:50 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Trying other indexer: TVmaze get_id_by_external
2017-09-06 02:22:50 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] Data returned from provider does not contain any torrents
2017-09-06 02:22:50 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] Search string: Marketplace (Canada) S44E08
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: http://api.tvmaze.com/lookup/shows?thetvdb=301236 [Status: 301]
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: http://api.tvmaze.com/shows/3081 [Status: 200]
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: http://api.tvmaze.com/shows/3081 [Status: 200]
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: https://api.themoviedb.org/3/configuration?api_key=**********
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Trying other indexer: TMDB get_id_by_external
2017-09-06 02:22:51 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent did not reach minimum ratio: [0.005/2.000]. Keeping it: [House.of.Cards.2013.S05E13.FiNAL.MULTi.1080p.WEBRip.x264-BRiNK]
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: https://api.themoviedb.org/3/find/301236?external_source=tvdb_id&api_key=**********
2017-09-06 02:22:51 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:52 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] GET URL: https://api.themoviedb.org/3/tv/63623/external_ids?api_key=**********
2017-09-06 02:22:52 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] User-Agent: Medusa/0.0.1(Linux; 4.9.35-v7+; f64cdcf4-9297-11e7-9527-b827eb6b4d4c)
2017-09-06 02:22:52 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Looking for externals using Trakt and tmdb id 63623
2017-09-06 02:22:52 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent completed and reached minimum ratio: [2.000/2.000] or seed idle limit: [30 min]. Removing it: [Ridiculousness.S09E14.720p.WEB.h264-TASTETV[rarbg]]
2017-09-06 02:22:52 DEBUG    TORRENTCHECKER :: [1d0d7ea] Transmission: Requested a POST connection to http://localhost:9091/transmission/rpc with params: None Data: {"arguments": {"ids": ["4dc3a6526f17420c3d44ab5c65d104ba292ed397"], "delete-local-data": 1}, "metho...
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/medusa/clients/torrent/generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "/home/pi/Medusa/lib/requests/sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/lib/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/lib/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/lib/requests/adapters.py", 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',))
2017-09-06 02:22:53 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] GET URL: http://forum.tntvillage.scambioetico.org/?filter=CBC+Marketplace+S44E08Marketplace+CA+S44E08Marketplace+S44E08Marketplace+%28Canada%29+S44E08&act=allreleases [Status: 200]
2017-09-06 02:22:53 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20130405 Firefox/22.0
2017-09-06 02:22:53 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent completed and reached minimum ratio but it was force started again. Current ratio: [0.000/0.000]. Keeping it: [running.wild.with.bear.grylls.s03e09.720p.web.x264-tbs.mkv]
2017-09-06 02:22:54 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Transaction with 6 queries executed
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [TNTVillage] :: [1d0d7ea] Data returned from provider does not contain any torrents
2017-09-06 02:22:54 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Retrieving show info from IMDb
2017-09-06 02:22:54 INFO     SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] Performing episode search for Marketplace
2017-09-06 02:22:54 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Loading show info from IMDb with ID: tt3986586
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] Search mode: Episode
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] Search show using search string: CBC Marketplace S44E08
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] GET URL: http://lolo.sickbeard.com/api?maxage=3000&cat=5000%2C5080%2C5020%2C5040%2C5050%2C5030%2C5060&q=CBC+Marketplace+S44E08&limit=100&t=search&offset=0 [Status: 200]
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] User-Agent: Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0;  rv:11.0) like Gecko
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] No results returned from provider. Check chosen Newznab search categories in provider settings and/or usenet retention
2017-09-06 02:22:54 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] Search show using search string: Marketplace CA S44E08
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] GET URL: http://lolo.sickbeard.com/api?maxage=3000&cat=5000%2C5080%2C5020%2C5040%2C5050%2C5030%2C5060&q=Marketplace+CA+S44E08&limit=100&t=search&offset=0 [Status: 200]
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] User-Agent: Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0;  rv:11.0) like Gecko
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] No results returned from provider. Check chosen Newznab search categories in provider settings and/or usenet retention
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] Search show using search string: Marketplace S44E08
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] GET URL: http://lolo.sickbeard.com/api?maxage=3000&cat=5000%2C5080%2C5020%2C5040%2C5050%2C5030%2C5060&q=Marketplace+S44E08&limit=100&t=search&offset=0 [Status: 200]
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] User-Agent: Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0;  rv:11.0) like Gecko
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] No results returned from provider. Check chosen Newznab search categories in provider settings and/or usenet retention
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] Search show using search string: Marketplace (Canada) S44E08
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] GET URL: http://lolo.sickbeard.com/api?maxage=3000&cat=5000%2C5080%2C5020%2C5040%2C5050%2C5030%2C5060&q=Marketplace+%28Canada%29+S44E08&limit=100&t=search&offset=0 [Status: 200]
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] User-Agent: Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0;  rv:11.0) like Gecko
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SickBeard Index] :: [1d0d7ea] No results returned from provider. Check chosen Newznab search categories in provider settings and/or usenet retention
2017-09-06 02:22:55 INFO     SEARCHQUEUE-FORCED-223161 :: [SceneAccess] :: [1d0d7ea] Performing episode search for Marketplace
2017-09-06 02:22:55 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent did not reach minimum ratio: [0.710/2.000]. Keeping it: [Booze.Traveler.S03E15.Siberia-Ice.Olated.Spirit.iNTERNAL.720p.HDTV.x264-DHD]
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SceneAccess] :: [1d0d7ea] Search mode: Episode
2017-09-06 02:22:55 DEBUG    SEARCHQUEUE-FORCED-223161 :: [SceneAccess] :: [1d0d7ea] Search string: CBC Marketplace S44E08
2017-09-06 02:22:56 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent did not reach minimum ratio: [0.008/3.000]. Keeping it: [Criminal.Minds.Beyond.Borders.S02E13.720p.HDTV.x264-KILLERS.mkv]
2017-09-06 02:22:56 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent did not reach minimum ratio: [0.000/2.000]. Keeping it: [Marketplace.S44E02.Food.Waste.720p.CBC.WEB.h264.AAC2.0.mkv]
2017-09-06 02:22:56 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent did not reach minimum ratio: [0.000/3.000]. Keeping it: [The.Island.With.Bear.Grylls.S04E04.720p.HDTV.x264-QPEL.mkv]
2017-09-06 02:22:56 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent completed and reached minimum ratio but it was force started again. Current ratio: [1.295/0.000]. Keeping it: [inside.the.fbi.new.york.s01e01.1080p.web.x264-tbs.mkv]
2017-09-06 02:22:56 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent did not reach minimum ratio: [1.133/4.000]. Keeping it: [mars.2016.s01e05.1080p.hdtv.x264-crooks.mkv]
2017-09-06 02:22:56 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent completed and reached minimum ratio but it was force started again. Current ratio: [0.274/0.000]. Keeping it: [VICE.S05E16.Last.Line.of.Defense.&.El.Rostro.720p.WEB-DL.AAC2.0.H.264-doosh.mkv]
2017-09-06 02:22:56 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] Getting all show data for 63623
2017-09-06 02:22:57 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Obtained info from IMDb: {u'rating': '7.1', u'votes': 16461, u'runtimes': 30, u'year': 2016, u'imdb_id': u'tt3986586', u'akas': u'', u'plot': u'Fuller House is a spin-off series based on the hit ABC family sitcom Full House (1987-95) created and executive produced by Jeff Franklin for Netflix. D.J. Tanner-Fuller (Candace Cameron-Bure) is a recently widowed mom to a 13-year-old named Jackson (Michael Campion), 7-year-old named Max (Elias Harger), and a newborn son named Tommy (Fox and Dashiell Messitt). After realizing she is unable to cope with the demands of holding a full time job as a veterinarian in addition to raising three kids, her sister Stephanie (Jodie Sweetin) and childhood best friend Kimmy (Andrea Barber), who is also the mother of a 13-year-old daughter (Soni Bringas), offer to move in to bring up her children.', u'genres': u'Comedy|Family', u'countries': u'UNITED STATES', u'title': u'Fuller House', u'last_update': 736578, u'country_codes': u'us', u'certificates': u'TV-G'}
2017-09-06 02:22:57 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Saving new IMDb show info to database
2017-09-06 02:22:57 DEBUG    SHOWQUEUE-SEASON-UPDATE :: [1d0d7ea] 301236: Saving to database: Fuller House
2017-09-06 02:22:57 INFO     TORRENTCHECKER :: [1d0d7ea] Torrent completed and reached minimum ratio: [2.000/2.000] or seed idle limit: [30 min]. Removing it: [Ridiculousness.S09E11.720p.WEB.h264-KLINGON[rarbg]]
2017-09-06 02:22:57 DEBUG    TORRENTCHECKER :: [1d0d7ea] Transmission: Requested a POST connection to http://localhost:9091/transmission/rpc with params: None Data: {"arguments": {"ids": ["5b0a67cf29330da08296ecfde9a8f81d738fd7ed"], "delete-local-data": 1}, "metho...
2017-09-06 02:22:57 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 0x6836c370>: Failed to establish a new connection: [Errno 111] Connection refused',))
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/clients/torrent/generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "/home/pi/Medusa/lib/requests/sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/lib/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/lib/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/lib/requests/adapters.py", 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 0x6836c370>: Failed to establish a new connection: [Errno 111] Connection refused',))

# Fixed code
def _get_auth(self):
    post_data = json.dumps(
        {
            "method": "session-get",
        }
    )

    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})

    # Validating Transmission authorization
    post_data = json.dumps(
        {
            "arguments": {},
            "method": "session-get",
        }
    )

    self._request(method="post", data=post_data)

    return self.auth