From d253f64c7f6aaefaa826e96ff19ebd584ea6fb38 Mon Sep 17 00:00:00 2001 From: Simon Robinson Date: Sat, 20 Jan 2024 14:47:00 +0000 Subject: [PATCH] Import `certifi` certificates when packaged using pyinstaller --- emailproxy.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/emailproxy.py b/emailproxy.py index 0144910..bf8c0f7 100644 --- a/emailproxy.py +++ b/emailproxy.py @@ -2490,6 +2490,16 @@ def init_platforms(self): # proxy's handling of this signal may change in future if other actions are seen as more suitable signal.signal(signal.SIGUSR1, lambda _signum, _fr: self.toggle_debug(Log.get_level() == logging.INFO)) + # certificates are not imported automatically when packaged using pyinstaller - we need certifi + if getattr(sys, 'frozen', False): + if ssl.get_default_verify_paths().cafile is None and 'SSL_CERT_FILE' not in os.environ: + try: + import certifi + os.environ['SSL_CERT_FILE'] = certifi.where() + Log.info('Running in a packaged/frozen environment - imported SSL certificates from `certifi`') + except ImportError: + Log.info('Unable to find `certifi` in a packaged/frozen environment - SSL connections may fail') + # noinspection PyUnresolvedReferences,PyAttributeOutsideInit def macos_nsworkspace_notification_listener_(self, notification): notification_name = notification.name()