# Buggy code
def getURL(
    url,
    post_data=None,
    params=None,
    headers=None,  # pylint:disable=too-many-arguments, too-many-return-statements, too-many-branches, too-many-locals
    timeout=30,
    session=None,
    **kwargs,
):
    """
    Returns data retrieved from the url provider.
    """
    response_type = kwargs.pop("returns", "response")
    stream = kwargs.pop("stream", False)
    hooks, cookies, verify, proxies = request_defaults(kwargs)
    method = "POST" if post_data else "GET"

    resp = session.request(
        method,
        url,
        data=post_data,
        params=params,
        timeout=timeout,
        allow_redirects=True,
        hooks=hooks,
        stream=stream,
        headers=headers,
        cookies=cookies,
        proxies=proxies,
        verify=verify,
    )

    if not resp.ok:
        logger.log(
            "Requested url {url} returned status code {status}: {desc}".format(
                url=url,
                status=resp.status_code,
                desc=http_code_description(resp.status_code),
            ),
            logger.DEBUG,
        )

    try:
        resp.raise_for_status()
    except requests.exceptions.RequestException as e:
        logger.log(
            "Error requesting url {resp.url}. Error: {msg}".format(
                resp=resp, msg=ex(e)
            ),
            logger.DEBUG,
        )
    except Exception as e:
        if "ECONNRESET" in e or (hasattr(e, "errno") and e.errno == errno.ECONNRESET):
            logger.log(
                "Connection reset by peer accessing url {resp.url}. Error: {msg}".format(
                    resp=resp, msg=ex(e)
                ),
                logger.WARNING,
            )
        else:
            logger.log(
                "Unknown exception in url {resp.url}. Error: {msg}".format(
                    resp=resp, msg=ex(e)
                ),
                logger.ERROR,
            )
            logger.log(traceback.format_exc(), logger.DEBUG)

    if not response_type or response_type == "response":
        return resp
    else:
        warnings.warn(
            "Returning {0} instead of {1} will be deprecated in the near future!".format(
                response_type, "response"
            ),
            PendingDeprecationWarning,
        )
        if response_type == "json":
            try:
                return resp.json()
            except ValueError:
                return {}
        else:
            return getattr(resp, response_type, resp)


# Traceback (ConnectionError)
DAILYSEARCHER :: [b9d562e] Exception generated in thread DAILYSEARCHER: error HTTPSConnectionPool(host='cdn.pymedusa.com', port=443): Max retries exceeded with url: /sb_network_timezones/network_timezones.txt (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x699fdbb0>: Failed to establish a new connection: [Errno -2] Nome ou servi\xc3\xa7o desconhecido',))
Traceback (most recent call last):
File "/home/osmc/SickRage/sickbeard/scheduler.py", line 106, in run
self.action.run(self.force)
File "/home/osmc/SickRage/sickbeard/dailysearcher.py", line 75, in run
update_network_dict()
File "/home/osmc/SickRage/sickbeard/network_timezones.py", line 47, in update_network_dict
url_data = helpers.getURL(url, session=helpers.make_session(), returns='text')
File "/home/osmc/SickRage/sickbeard/helpers.py", line 1423, in getURL
verify=verify)
File "/home/osmc/SickRage/lib/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/home/osmc/SickRage/lib/requests/sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "/home/osmc/SickRage/lib/cachecontrol/adapter.py", line 46, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/home/osmc/SickRage/lib/requests/adapters.py", line 467, in send
raise ConnectionError(e, request=request)
ConnectionError: HTTPSConnectionPool(host='cdn.pymedusa.com', port=443): Max retries exceeded with url: /sb_network_timezones/network_timezones.txt (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x699fdbb0>: Failed to establish a new connection: [Errno -2] Nome ou servi\xc3\xa7o desconhecido',))

# Fixed code
def getURL(
    url,
    post_data=None,
    params=None,
    headers=None,  # pylint:disable=too-many-arguments, too-many-return-statements, too-many-branches, too-many-locals
    timeout=30,
    session=None,
    **kwargs,
):
    """
    Returns data retrieved from the url provider.
    """
    response_type = kwargs.pop("returns", "response")
    stream = kwargs.pop("stream", False)
    hooks, cookies, verify, proxies = request_defaults(kwargs)
    method = "POST" if post_data else "GET"

    try:
        resp = session.request(
            method,
            url,
            data=post_data,
            params=params,
            timeout=timeout,
            allow_redirects=True,
            hooks=hooks,
            stream=stream,
            headers=headers,
            cookies=cookies,
            proxies=proxies,
            verify=verify,
        )

        if not resp.ok:
            logger.log(
                "Requested url {url} returned status code {status}: {desc}".format(
                    url=url,
                    status=resp.status_code,
                    desc=http_code_description(resp.status_code),
                ),
                logger.DEBUG,
            )

    except requests.exceptions.RequestException as e:
        logger.log(
            "Error requesting url {resp.url}. Error: {msg}".format(
                resp=resp, msg=ex(e)
            ),
            logger.DEBUG,
        )
    except Exception as e:
        if "ECONNRESET" in e or (hasattr(e, "errno") and e.errno == errno.ECONNRESET):
            logger.log(
                "Connection reset by peer accessing url {resp.url}. Error: {msg}".format(
                    resp=resp, msg=ex(e)
                ),
                logger.WARNING,
            )
        else:
            logger.log(
                "Unknown exception in url {resp.url}. Error: {msg}".format(
                    resp=resp, msg=ex(e)
                ),
                logger.ERROR,
            )
            logger.log(traceback.format_exc(), logger.DEBUG)

    if not response_type or response_type == "response":
        return resp
    else:
        warnings.warn(
            "Returning {0} instead of {1} will be deprecated in the near future!".format(
                response_type, "response"
            ),
            PendingDeprecationWarning,
        )
        if response_type == "json":
            try:
                return resp.json()
            except ValueError:
                return {}
        else:
            return getattr(resp, response_type, resp)