From 1dd4afa5e2ec607893fd7e362d34b0cde3e867d5 Mon Sep 17 00:00:00 2001 From: Safihre Date: Tue, 11 Aug 2020 22:21:14 +0200 Subject: [PATCH] Generalize use of certifi module --- SABnzbd.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/SABnzbd.py b/SABnzbd.py index 51ea24a..c253822 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -24,6 +24,7 @@ if sys.hexversion < 0x03050000: import logging import logging.handlers +import importlib.util import traceback import getopt import signal @@ -36,18 +37,16 @@ import re try: import Cheetah - - if Cheetah.Version[0] != "3": - raise ValueError import feedparser import configobj import cherrypy import portend import cryptography import chardet -except ValueError: - print("Sorry, requires Python module Cheetah 3 or higher.") - sys.exit(1) + + if Cheetah.Version[0] != "3": + print("Sorry, requires Python module Cheetah 3 or higher.") + sys.exit(1) except ImportError as e: print("Not all required Python modules are available, please check requirements.txt") print("Missing module:", e.name) @@ -1168,12 +1167,14 @@ def main(): # SSL Information logging.info("SSL version = %s", ssl.OPENSSL_VERSION) - # Load (extra) certificates in the binary distributions - if hasattr(sys, "frozen") and (sabnzbd.WIN32 or sabnzbd.DARWIN): - # The certifi package brings the latest certificates on build - # This will cause the create_default_context to load it automatically - os.environ["SSL_CERT_FILE"] = os.path.join(sabnzbd.DIR_PROG, "cacert.pem") - logging.info("Loaded additional certificates from %s", os.environ["SSL_CERT_FILE"]) + # Load (extra) certificates if supplied by certifi + # This is optional and provided in the binaries + if importlib.util.find_spec("certifi") is not None: + import certifi + + os.environ["SSL_CERT_FILE"] = certifi.where() + logging.info("Certifi version: %s", certifi.__version__) + logging.info("Loaded additional certificates from: %s", os.environ["SSL_CERT_FILE"]) # Extra startup info if sabnzbd.cfg.log_level() > 1: