From 5835c609b721f540ee8f1f2b27e438393abb462d Mon Sep 17 00:00:00 2001 From: Vinay Kumar Date: Tue, 11 Aug 2026 12:38:09 +0530 Subject: [PATCH] Fix SSL certificate loading on macOS systems This fix addresses the issue where HTTPie fails to verify SSL certificates on macOS systems even when certifi is installed. The problem occurs because the default certificate loading mechanism doesn't work properly on macOS, causing "SSLCertVerificationError: certificate verify failed: unable to get local issuer certificate" errors. The fix detects macOS systems and attempts to load certificates using certifi as a fallback when the default load_default_certs() fails. --- httpie/compat.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/httpie/compat.py b/httpie/compat.py index d12abcff02..eda13d75da 100644 --- a/httpie/compat.py +++ b/httpie/compat.py @@ -12,6 +12,7 @@ cookiejar.DefaultCookiePolicy = HTTPieCookiePolicy is_windows = 'win32' in str(sys.platform).lower() +is_macos = 'darwin' in str(sys.platform).lower() is_frozen = getattr(sys, 'frozen', False) MIN_SUPPORTED_PY_VERSION = (3, 7) @@ -110,4 +111,19 @@ def ensure_default_certs_loaded(ssl_context: SSLContext) -> None: """ if hasattr(ssl_context, 'load_default_certs'): if not ssl_context.get_ca_certs(): - ssl_context.load_default_certs() + # On macOS, we need to ensure certificates are loaded properly + # This fixes the issue where SSL certificates aren't loaded correctly + # on macOS systems, causing "CERTIFICATE_VERIFY_FAILED" errors + try: + ssl_context.load_default_certs() + except Exception: + # If load_default_certs fails, try alternative approaches + # For macOS specifically, we might need to use certifi + if is_macos: + try: + import certifi + ssl_context.load_verify_locations(certifi.where()) + except ImportError: + # If certifi is not available, we can't do much more + # The error will be raised by the SSL context when needed + pass \ No newline at end of file