# Buggy code
def download_models(
    content_model_path=DEFAULT_CONTENT_MODEL_PATH,
    subject_model_path=DEFAULT_SUBJECT_MODEL_PATH,
    twentysixhundred_model_path=DEFAULT_2600_MODEL_PATH,
    on_error=None,
):
    """Download models

    Calls on_error(primary_message, secondary_message) in case of error

    Returns success as boolean value
    """
    from urllib2 import urlopen, URLError, HTTPError
    from httplib import HTTPException
    import socket

    if HAVE_CERTIFI:
        cafile = certifi.where()
    else:
        cafile = None
    for url, fn in (
        (URL_CLINTON_SUBJECT, subject_model_path),
        (URL_CLINTON_CONTENT, content_model_path),
        (URL_2600, twentysixhundred_model_path),
    ):
        if os.path.exists(fn):
            logger.debug("File %s already exists", fn)
            continue
        logger.info("Downloading %s to %s", url, fn)
        try:
            resp = urlopen(url, cafile=cafile)
            with open(fn, "wb") as f:
                f.write(resp.read())
        except (URLError, HTTPError, HTTPException, socket.error) as exc:
            msg = _("Downloading url failed: %s") % url
            msg2 = "{}: {}".format(type(exc).__name__, exc)
            logger.exception(msg)
            if on_error:
                on_error(msg, msg2)
            from bleachbit.FileUtilities import delete

            delete(fn, ignore_missing=True)  # delete any partial download
            return False
    return True


# Traceback (IOError)
Automatically preserving language en.
Downloading https://sourceforge.net/projects/bleachbit/files/chaff/clinton_subject_model.json.bz2/download to B:\BleachBit-Portable\clinton_subject_model.json.bz2
Traceback (most recent call last):
File "bleachbit\GuiChaff.pyo", line 160, in on_make_files
File "bleachbit\GuiChaff.pyo", line 140, in download_models_dialog
File "bleachbit\GuiChaff.pyo", line 130, in download_models_gui
File "bleachbit\Chaff.pyo", line 141, in download_models
File "urllib2.pyo", line 144, in urlopen
File "ssl.pyo", line 440, in create_default_context
IOError: [Errno 2] No such file or directory

# Fixed code
def download_models(
    content_model_path=DEFAULT_CONTENT_MODEL_PATH,
    subject_model_path=DEFAULT_SUBJECT_MODEL_PATH,
    twentysixhundred_model_path=DEFAULT_2600_MODEL_PATH,
    on_error=None,
):
    """Download models

    Calls on_error(primary_message, secondary_message) in case of error

    Returns success as boolean value
    """
    from urllib2 import urlopen, URLError, HTTPError
    from httplib import HTTPException
    import socket

    for url, fn in (
        (URL_CLINTON_SUBJECT, subject_model_path),
        (URL_CLINTON_CONTENT, content_model_path),
        (URL_2600, twentysixhundred_model_path),
    ):
        if os.path.exists(fn):
            logger.debug("File %s already exists", fn)
            continue
        logger.info("Downloading %s to %s", url, fn)
        try:
            resp = urlopen(url, cafile=CA_BUNDLE)
            with open(fn, "wb") as f:
                f.write(resp.read())
        except (URLError, HTTPError, HTTPException, socket.error) as exc:
            msg = _("Downloading url failed: %s") % url
            msg2 = "{}: {}".format(type(exc).__name__, exc)
            logger.exception(msg)
            if on_error:
                on_error(msg, msg2)
            from bleachbit.FileUtilities import delete

            delete(fn, ignore_missing=True)  # delete any partial download
            return False
    return True