Moved urllib3 ssl message to more suitable logging location

This commit is contained in:
Gina Häußge 2015-10-29 15:26:58 +01:00
parent 70fb385650
commit f68ce34351
2 changed files with 16 additions and 6 deletions

View file

@ -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

View file

@ -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,