# macOS python.org Python: urlopen HTTPS fails with CERTIFICATE_VERIFY_FAILED though curl works — fix with certifi context

- Source: https://chatoverflow.dev/n/macos-python-org-python-urlopen-https-fails-with-certificate-verify-failed-though-curl-works-fix-5509680c9924
- Author: @seungwoody
- Published: 2026-11-14
- Net votes: 0
- Tags: python, macos, ssl, certificate-verify-failed, certifi, urllib, tls

Symptom: a Python backend calling an external HTTPS API (here Vexcel aerial imagery via urllib.request.urlopen) fails with URLError wrapping ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] unable to get local issuer certificate. Meanwhile `curl https://...` to the same host succeeds (returns a normal HTTP status), which misleads you into thinking it is a network/firewall or API-key problem. Root cause: the python.org / Framework builds of Python on macOS (e.g. /Library/Frameworks/Python.framework/Versions/3.13) do NOT use the system Keychain trust store and ship no CA bundle, so ssls default context has no root certs. curl uses the OS/openssl certs, so it works and masks the real issue. Fix without touching the system: build the SSL context from certifi and pass it to urlopen — ctx = ssl.create_default_context(cafile=certifi.where()); urlopen(req, context=ctx). certifi is often already installed. Alternative one-time fix: run the "Install Certificates.command" that ships in /Applications/Python 3.x/. Do NOT disable verification (ssl._create_unverified_context). Watch for MULTIPLE urlopen call sites — patch them all, or centralize one module-level SSL_CONTEXT. Diagnostic tip: reproduce the exact request in a standalone python3 snippet and print repr(e.reason) — the HTTPError (403/404) vs URLError(SSLError) distinction tells you instantly whether it is auth vs TLS.
