ageron/handson-mlp

[bug] ssl error on mac

Open

#7 创建于 2025年11月1日

在 GitHub 查看
 (1 评论) (0 反应) (1 负责人)Jupyter Notebook (513 fork)github user discovery
bughelp wanted

仓库指标

Star
 (1,561 star)
PR 合并指标
 (PR 指标待抓取)

描述

Enter the chapter number

ch 2

Enter the page number

No response

What is the cell's number in the notebook

13

Enter the environment you are using to run the notebook

Jupyter on MacOS

Describe your issue

Hi Aurélien,

Congratulations on the new edition! I just started working through Chapter 2 and ran into a cross-platform SSL issue with the data download that I thought you might find useful to know about.

Issue

The original urllib.request.urlretrieve() approach can hit SSL certificate verification errors on macOS (and potentially corporate networks), causing the notebook to fail for some users.

Original Code

def load_housing_data():
    tarball_path = Path() / "datasets" / "housing" / "housing.tgz"
    if not tarball_path.is_file():
        Path("datasets/housing").mkdir(parents=True, exist_ok=True)
        url = "https://github.com/ageron/data/raw/main/housing.tgz"
        urllib.request.urlretrieve(url, tarball_path)
    # ... rest of function

Suggested Improvement

def load_housing_data():
    tarball_path = DATA_DIR / "housing.tgz"
    if not tarball_path.is_file():
        DATA_DIR.mkdir(parents=True, exist_ok=True)
        url = "https://github.com/ageron/data/raw/main/housing.tgz"
        
        # Use requests library for clean, cross-platform downloads
        response = requests.get(url)
        response.raise_for_status()  # Raises an exception for bad status codes
        
        with open(tarball_path, 'wb') as f:
            f.write(response.content)
    # ... rest of function

Benefits

  • Works consistently across Windows, macOS, and Linux
  • Better error handling with clear messages
  • No SSL certificate workarounds needed
  • requests is already a common dependency in ML workflows

Thanks for the excellent book! Looking forward to applying these techniques!

Best regards, John

Enter what you expected to happen

No response

If you found a workaround, describe it here

No response

贡献者指南