# Buggy code
def _request(self, method="get", params=None, data=None, files=None, cookies=None):
    if time.time() > self.last_time + 1800 or not self.auth:
        self.last_time = time.time()
        self._get_auth()

    text_params = str(params)
    text_data = str(data)
    text_files = str(files)
    log.debug(
        "{name}: Requested a {method} connection to {url} with"
        " params: {params} Data: {data} Files: {files}",
        {
            "name": self.name,
            "method": method.upper(),
            "url": self.url,
            "params": text_params[0:99] + "..."
            if len(text_params) > 102
            else text_params,
            "data": text_data[0:99] + "..." if len(text_data) > 102 else text_data,
            "files": text_files[0:99] + "..." if len(text_files) > 102 else text_files,
        },
    )

    if not self.auth:
        log.warning("{name}: Authentication Failed", {"name": self.name})

        return False
    try:
        self.response = self.session.request(
            method,
            self.url,
            params=params,
            data=data,
            files=files,
            cookies=cookies,
            timeout=120,
            verify=False,
        )
    except requests.exceptions.ConnectionError as msg:
        log.error(
            "{name}: Unable to connect {error}", {"name": self.name, "error": msg}
        )
        return False
    except (requests.exceptions.MissingSchema, requests.exceptions.InvalidURL):
        log.error("{name}: Invalid Host", {"name": self.name})
        return False
    except requests.exceptions.HTTPError as msg:
        log.error(
            "{name}: Invalid HTTP Request {error}", {"name": self.name, "error": msg}
        )
        return False
    except requests.exceptions.Timeout as msg:
        log.warning(
            "{name}: Connection Timeout {error}", {"name": self.name, "error": msg}
        )
        return False
    except Exception as msg:
        log.error(
            "{name}: Unknown exception raised when send torrent to {name} : {error}",
            {"name": self.name, "error": msg},
        )
        return False

    if self.response.status_code == 401:
        log.error(
            "{name}: Invalid Username or Password, check your config",
            {"name": self.name},
        )
        return False

    code_description = http_code_description(self.response.status_code)

    if code_description is not None:
        log.info("{name}: {code}", {"name": self.name, "code": code_description})
        return False

    log.debug(
        "{name}: Response to {method} request is {response}",
        {
            "name": self.name,
            "method": method.upper(),
            "response": self.response.text[0:1024] + "..."
            if len(self.response.text) > 1027
            else self.response.text,
        },
    )

    return True


# Traceback (ChunkedEncodingError)
2018-12-27 14:51:38 DEBUG    APIv2-Thread_1 :: [918cfe7] Broken providers already updated in the last hour
2018-12-27 14:52:06 INFO     SNATCHQUEUE-SNATCH-255097 :: [918cfe7] Beginning to snatch release: Burger.Quiz.-.S03E05.HDTV.1080p.MKV.AC-3.Fr.du.12.d��cembre.2018.Diablo
2018-12-27 14:52:06 INFO     SNATCHQUEUE-SNATCH-255097 :: [918cfe7] Downloading Burger.Quiz.-.S03E05.HDTV.1080p.MKV.AC-3.Fr.du.12.d��cembre.2018.Diablo with 92 seeders and 0 leechers and size 1.09 GB from Yggtorrent, through a SearchType.MANUAL_SEARCH search
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] GET URL: https://www.yggtorrent.to/user/ajax_usermenu [Status: 301]
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] GET URL: https://www2.yggtorrent.gg/user/ajax_usermenu [Status: 200]
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] GET URL: https://www.yggtorrent.to/engine/download_torrent?id=368341 [Status: 301]
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] GET URL: https://www2.yggtorrent.gg/engine/download_torrent?id=368341 [Status: 200]
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:07 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] Calling DownloadStation Client
2018-12-27 14:52:10 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] GET URL: https://localhost:5001/webapi/auth.cgi?session=DownloadStation&account=**********&version=2&format=cookie&passwd=C0yu%2F612&api=SYNO.API.Auth&method=login [Status: 200]
2018-12-27 14:52:10 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:12 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] GET URL: https://localhost:5001/webapi/DownloadStation/info.cgi?session=DownloadStation&api=SYNO.DownloadStation.Info&version=2&method=getinfo [Status: 200]
2018-12-27 14:52:12 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:12 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] Add torrent files with data: {"session": "DownloadStation", "api": "SYNO.DownloadStation.Task", "version": "1", "method": "create"}
2018-12-27 14:52:12 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] DownloadStation: Requested a POST connection to https://localhost:5001/webapi/DownloadStation/task.cgi with params: None Data: {u'session': u'DownloadStation', u'api': u'SYNO.DownloadStation.Task', u'version': u'1', u'method':... Files: {u'file': (u'Burger.Quiz.-.S03E05.HDTV.1080p.MKV.AC-3.Fr.du.12.d\xe9cembre.2018.Diablo.torrent', 'd...
2018-12-27 14:52:14 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] POST URL: https://localhost:5001/webapi/DownloadStation/task.cgi [Status: 200]
2018-12-27 14:52:14 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] User-Agent: Medusa/0.2.14 (Linux; 3.2.40; 771abe7a-09a8-11e9-a990-001132301ff6)
2018-12-27 14:52:14 DEBUG    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] With post data: -cb566858bbfeb6edf40939a1de78c68b Content-Disposition: form-data; name="session"  DownloadStati...
2018-12-27 14:52:14 ERROR    SNATCHQUEUE-SNATCH-255097 :: [918cfe7] DownloadStation: Unknown exception raised when send torrent to DownloadStation : ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/clients/torrent/generic.py", line 82, in _request
    cookies=cookies, timeout=120, verify=False)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/session/core.py", line 102, in request
    timeout=timeout, verify=ssl_cert, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/ext/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/ext/requests/sessions.py", line 686, in send
    r.content
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/ext/requests/models.py", line 828, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/ext/requests/models.py", line 753, in generate
    raise ChunkedEncodingError(e)
ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))

# Fixed code
def _request(self, method="get", params=None, data=None, files=None, cookies=None):
    if time.time() > self.last_time + 1800 or not self.auth:
        self.last_time = time.time()
        self._get_auth()

    text_params = str(params)
    text_data = str(data)
    text_files = str(files)
    log.debug(
        "{name}: Requested a {method} connection to {url} with"
        " params: {params} Data: {data} Files: {files}",
        {
            "name": self.name,
            "method": method.upper(),
            "url": self.url,
            "params": text_params[0:99] + "..."
            if len(text_params) > 102
            else text_params,
            "data": text_data[0:99] + "..." if len(text_data) > 102 else text_data,
            "files": text_files[0:99] + "..." if len(text_files) > 102 else text_files,
        },
    )

    if not self.auth:
        log.warning("{name}: Authentication Failed", {"name": self.name})

        return False
    try:
        self.response = self.session.request(
            method,
            self.url,
            params=params,
            data=data,
            files=files,
            cookies=cookies,
            timeout=120,
            verify=False,
        )
    except (requests.exceptions.MissingSchema, requests.exceptions.InvalidURL) as error:
        log.warning(
            "{name}: Invalid Host: {error}", {"name": self.name, "error": error}
        )
        return False
    except requests.exceptions.RequestException as error:
        log.warning(
            "{name}: Error occurred during request: {error}",
            {"name": self.name, "error": error},
        )
        return False
    except Exception as error:
        log.error(
            "{name}: Unknown exception raised when sending torrent to {name}: {error}",
            {"name": self.name, "error": error},
        )
        return False

    if self.response.status_code == 401:
        log.error(
            "{name}: Invalid Username or Password, check your config",
            {"name": self.name},
        )
        return False

    code_description = http_code_description(self.response.status_code)

    if code_description is not None:
        log.info("{name}: {code}", {"name": self.name, "code": code_description})
        return False

    log.debug(
        "{name}: Response to {method} request is {response}",
        {
            "name": self.name,
            "method": method.upper(),
            "response": self.response.text[0:1024] + "..."
            if len(self.response.text) > 1027
            else self.response.text,
        },
    )

    return True