Repository navigation
fix(datasets): verify downloads against certifi's CA certificates too - #60
Merged
Merged
Conversation
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.
|
Docs preview: https://pr-60.eigenkit-docs.pages.dev |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On the python.org build of Python for macOS, every dataset that eigenkit downloads (
concrete,beijing_pm25) fails on first use withssl.SSLCertVerificationError: certificate verify failed: unable to get local issuer certificate. That build has no CA certificates until the user runsInstall Certificates.command, andcached_downloadusedurlretrieve, which takes the default SSL context.certifi>=2024.7.4joins thedatasetsextra, so afterpip install eigenkit[datasets]the download works with no manual step.read()without a size raisesIncompleteReadon a body shorter than itsContent-Length, asurlretrievedid. The file is read into memory; the registry's datasets are a few MB.docs/user-guide/datasets.mdgets a section on downloads and certificates. scikit-learn downloadscalifornia_housingitself with Python's own certificates, so on that build it still needsInstall Certificates.command, and the section says so.urlretrievenow fakeurlopen.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.pywas loaded.urlretrieveof the dataset URL, which the old code ran, raisesURLError: SSLCertVerificationError(... unable to get local issuer certificate).After, with certifi:
beijing_pm25.csvdownloads (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.tests/datasets/test_cache.py, both failing before the change:SSL_CERT_FILEandSSL_CERT_DIRpointing at nothing, as on that build, the download context still holds CA certificates;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_downloadchange, that isconcreteandbeijing_pm25. certifi's roots, the Mozilla set thatrequestsand pip use, are trusted on top of the system's, so a CA trusted through the system orSSL_CERT_FILEstill verifies. A certificate error now raisesssl.SSLCertVerificationErroritself instead of aurllib.error.URLErrorthat wraps it. Both areOSError, but code that catches onlyURLErrorno longer catches this one. Thedatasetsextra gains one small dependency that has no dependencies of its own.