Skip to content

fix(datasets): verify downloads against certifi's CA certificates too - #60

Merged
sarseniy merged 1 commit into
mainfrom
fix/datasets-ssl-certificates
Nov 12, 2026
Merged

sarseniy merged 1 commit into
mainfrom
fix/datasets-ssl-certificates

Conversation

@sarseniy

Copy link
Copy Markdown
Contributor

Summary

On the python.org build of Python for macOS, every dataset that eigenkit downloads (concrete, beijing_pm25) fails on first use with ssl.SSLCertVerificationError: certificate verify failed: unable to get local issuer certificate. That build has no CA certificates until the user runs Install Certificates.command, and cached_download used urlretrieve, which takes the default SSL context.

 cached_download(url, filename, expected_hash)
-  urlretrieve(url, partial)
+  context = create_default_context()        # system CAs, SSL_CERT_FILE
+  context.load_verify_locations(certifi)    # added, not substituted; when installed
+  urlopen(url, context=context).read() -> partial
+  on SSLCertVerificationError
+    raise it again with what to do: Install Certificates.command, certifi, SSL_CERT_FILE
  • certifi>=2024.7.4 joins the datasets extra, so after pip install eigenkit[datasets] the download works with no manual step.
  • read() without a size raises IncompleteRead on a body shorter than its Content-Length, as urlretrieve did. The file is read into memory; the registry's datasets are a few MB.
  • docs/user-guide/datasets.md gets a section on downloads and certificates. scikit-learn downloads california_housing itself with Python's own certificates, so on that build it still needs Install Certificates.command, and the section says so.
  • The test fakes of urlretrieve now fake urlopen.

Evidence

On python.org Python 3.11.6 for macOS with no CA certificates installed, against the real dataset URLs. eigenkit needs Python 3.12, so only _cache.py was loaded.

  • Before: urlretrieve of the dataset URL, which the old code ran, raises URLError: SSLCertVerificationError(... unable to get local issuer certificate).
    After, with certifi: beijing_pm25.csv downloads (2,010,753 bytes), its hash matches, and it is cached.
    After, without certifi: SSLCertVerificationError: Could not verify the TLS certificate of https://kit.eigenorbit.com/datasets/beijing_pm25.csv: ... run 'Install Certificates.command' ..., and the cache stays empty.
  • Two new tests in tests/datasets/test_cache.py, both failing before the change:
    • with SSL_CERT_FILE and SSL_CERT_DIR pointing at nothing, as on that build, the download context still holds CA certificates;
    • a certificate error names the fix and leaves no partial file behind.
  • pytest tests/datasets tests/benchmark: 263 passed. pre-commit and the docs checks pass.

Merge Danger

Door: two-way

Blast Radius: datasets

Only downloads through cached_download change, that is concrete and beijing_pm25. certifi's roots, the Mozilla set that requests and pip use, are trusted on top of the system's, so a CA trusted through the system or SSL_CERT_FILE still verifies. A certificate error now raises ssl.SSLCertVerificationError itself instead of a urllib.error.URLError that wraps it. Both are OSError, but code that catches only URLError no longer catches this one. The datasets extra gains one small dependency that has no dependencies of its own.

On the python.org build of Python for macOS, every downloaded dataset
(concrete, beijing_pm25) failed on first use with "certificate verify
failed: unable to get local issuer certificate": that build has no CA
certificates until Install Certificates.command runs, and the download
used urlretrieve with the default SSL context.

cached_download now downloads with urlopen and a context that trusts the
system's CA certificates plus certifi's, when certifi is installed. The
datasets extra installs certifi. If verification still fails, the error
says what to do: run Install Certificates.command, install certifi, or
set SSL_CERT_FILE.
@github-actions

Copy link
Copy Markdown

Docs preview: https://pr-60.eigenkit-docs.pages.dev

@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/eigenkit/datasets
  _cache.py 51-52
Project Total  

This report was generated by python-coverage-comment-action

@sarseniy
sarseniy merged commit 786fd5d into main Nov 12, 2026
17 checks passed
@sarseniy
sarseniy deleted the fix/datasets-ssl-certificates branch November 12, 2026 16:37

This branch was successfully deployed

1 active deployment
docs-preview — ce0c149c Deployed Nov 12, 2026 by sarseniy via preview #83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant