From f68ce3435125d55906ac7e65442ef1906a291777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 29 Oct 2015 15:26:58 +0100 Subject: [PATCH] Moved urllib3 ssl message to more suitable logging location --- src/octoprint/__init__.py | 12 ++++++------ src/octoprint/cli/server.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index 1ccdc835..485f7214 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -23,18 +23,18 @@ logging.basicConfig() #~~ try to ensure a sound SSL environment +urllib3_ssl = True +"""Whether requests/urllib3 and urllib3 (if installed) should be able to establish + a sound SSL environment or not.""" + version_info = sys.version_info if version_info.major == 2 and version_info.minor <= 7 and version_info.micro < 9: - message = "Cannot configure PyOpenSSL for {} to ensure a secure " + \ - "SSL environment, update to Python >= 2.7.9 or install PyOpenSSL, see " + \ - "https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl" - try: # make sure our requests version of urllib3 is properly patched (if possible) import requests.packages.urllib3.contrib.pyopenssl requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3() except ImportError: - logging.getLogger(__name__).warn(message.format("requests/urllib3")) + urllib3_ssl = False try: import urllib3 @@ -45,7 +45,7 @@ if version_info.major == 2 and version_info.minor <= 7 and version_info.micro < import urllib3.contrib.pyopenssl urllib3.contrib.pyopenssl.inject_into_urllib3() except ImportError: - logging.getLogger(__name__).warn(message.format("urllib3")) + urllib3_ssl = False except ImportError: pass diff --git a/src/octoprint/cli/server.py b/src/octoprint/cli/server.py index 74b6b794..f5505feb 100644 --- a/src/octoprint/cli/server.py +++ b/src/octoprint/cli/server.py @@ -17,6 +17,16 @@ def run_server(basedir, configfile, host, port, debug, allow_root, logging_confi def log_startup(_): logging.getLogger("octoprint.server").info("Starting OctoPrint {}".format(__display_version__)) + from octoprint import urllib3_ssl + if not urllib3_ssl: + logging.getLogger("octoprint.server")\ + .warn("requests/urllib3 will run in an insecure SSL environment. " + "You might see corresponding warnings logged later " + "(\"InsecurePlatformWarning\"). It is recommended to either " + "update to a Python version >= 2.7.9 or alternatively " + "install PyOpenSSL plus its dependencies. For details see " + "https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl") + settings, _, plugin_manager = init_platform(basedir, configfile, logging_file=logging_config,