# Buggy code
def login(self):
    """Login method used for logging in before doing search and torrent downloads."""
    if any(dict_from_cookiejar(self.session.cookies).values()):
        return True

    if "pass" in dict_from_cookiejar(self.session.cookies):
        return True

    login_html = self.session.get(self.urls["login"])
    with BS4Parser(login_html.text, "html5lib") as html:
        token = html.find("input", attrs={"name": "_token"}).get("value")

    login_params = {
        "_token": token,
        "email_username": self.username,
        "password": self.password,
        "remember": 1,
        "submit": "Login",
    }

    response = self.session.post(self.urls["login"], data=login_params)
    if not response or not response.text:
        log.warning("Unable to connect to provider")
        return False

    if "These credentials do not match our records." in response.text:
        log.warning("Invalid username or password. Check your settings")
        return False

    return True


# Traceback (AttributeError)
2020-01-19 18:56:38 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BTDB] :: [68f8328] Error requesting url https://btdb.eu/recent Error: HTTPSConnectionPool(host='btdb.eu', port=443): Max retries exceeded with url: /recent?category=show (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x6d3b9030>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
2020-01-19 18:56:38 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BTDB] :: [68f8328] No data returned from provider
2020-01-19 18:56:38 INFO     SEARCHQUEUE-DAILY-SEARCH :: [BTDB] :: [68f8328] Removing cache entries older than 15 days from btdb
2020-01-19 18:56:38 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [PrivateHD] :: [68f8328] Updating providers cache
2020-01-19 18:57:06 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [PrivateHD] :: [68f8328] Error requesting url https://privatehd.to/auth/login Error: HTTPSConnectionPool(host='privatehd.to', port=443): Max retries exceeded with url: /auth/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x6c97dc70>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
2020-01-19 18:57:06 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [PrivateHD] :: [68f8328] DailySearchQueueItem Exception, error: AttributeError("'NoneType' object has no attribute 'text'")
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/search/queue.py", line 266, in run
    found_results = search_for_needed_episodes(self.scheduler_start_time, force=self.force)
  File "/home/pi/Medusa/medusa/search/core.py", line 526, in search_for_needed_episodes
    cur_provider.cache.update_cache(scheduler_start_time)
  File "/home/pi/Medusa/medusa/tv/cache.py", line 225, in update_cache
    data = self._get_rss_data()
  File "/home/pi/Medusa/medusa/tv/cache.py", line 200, in _get_rss_data
    return {'entries': self.provider.search(self.search_params)}
  File "/home/pi/Medusa/medusa/providers/torrent/html/privatehd.py", line 62, in search
    if not self.login():
  File "/home/pi/Medusa/medusa/providers/torrent/html/privatehd.py", line 151, in login
    with BS4Parser(login_html.text, 'html5lib') as html:
AttributeError: 'NoneType' object has no attribute 'text'

# Fixed code
def login(self):
    """Login method used for logging in before doing search and torrent downloads."""
    if any(dict_from_cookiejar(self.session.cookies).values()):
        return True

    if "pass" in dict_from_cookiejar(self.session.cookies):
        return True

    login_html = self.session.get(self.urls["login"])
    if not login_html or not login_html.text:
        log.warning("Unable to connect to provider")
        return False
    with BS4Parser(login_html.text, "html5lib") as html:
        token = html.find("input", attrs={"name": "_token"}).get("value")

    login_params = {
        "_token": token,
        "email_username": self.username,
        "password": self.password,
        "remember": 1,
        "submit": "Login",
    }

    response = self.session.post(self.urls["login"], data=login_params)
    if not response or not response.text:
        log.warning("Unable to connect to provider")
        return False

    if "These credentials do not match our records." in response.text:
        log.warning("Invalid username or password. Check your settings")
        return False

    return True