Skip to content

Instantly share code, notes, and snippets.

View href's full-sized avatar
🦀

Denis Krienbühl href

🦀
View GitHub Profile
@href
href / README.md
Last active October 17, 2022 07:18
Self-signed certificates support for macOS keychain with any CPython

When trying to connect to an endpoint with a certificate of a custom certificate authority, stored in the macOS keychain, Python generally raises errors like SSL: CERTIFICATE_VERIFY_FAILED.

They can be avoided by exporting the certs locally, and pointing modules like urllib2 or requests to it:

security export -t certs -f pemseq -k keychain.login > ~/keychain.pem
security export -t certs -f pemseq -k /Library/Keychains/System.keychain >> ~/keychain.pem
security export -t certs -f pemseq -k /System/Library/Keychains/SystemRootCertificates.keychain >> ~/keychain.pem

export REQUESTS_CA_BUNDLE="$HOME/keychain.pem"