Skip to content

Commit

Permalink
attempt to fix issue #126 Python 2.7.9 + SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Wahl committed Dec 21, 2014
1 parent 03e4b7e commit 1f99d2f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Nagstamon/Nagstamon/Actions.py
Expand Up @@ -31,7 +31,8 @@


# if running on windows import winsound # if running on windows import winsound
import platform import platform
if platform.system() == "Windows": if platform.system() == "Windows":# necessary for Python-2.7.9-ssl-support-fix https://github.com/HenriWahl/Nagstamon/issues/126

import winsound import winsound


# Garbage collection # Garbage collection
Expand Down Expand Up @@ -830,30 +831,33 @@ def BuildURLOpener(server):
The MultipartPostHandler is needed for submitting multipart forms from Opsview The MultipartPostHandler is needed for submitting multipart forms from Opsview
""" """
# trying with changed digest/basic auth order as some digest auth servers do not # trying with changed digest/basic auth order as some digest auth servers do not
# seem to work wi the previous way # seem to work the previous way
if str(server.use_proxy) == "False": if str(server.use_proxy) == "False":
server.proxy_handler = urllib2.ProxyHandler({}) server.proxy_handler = urllib2.ProxyHandler({})
urlopener = urllib2.build_opener(server.digest_handler,\ urlopener = urllib2.build_opener(server.digest_handler,
server.basic_handler,\ server.basic_handler,
server.proxy_handler,\ server.proxy_handler,
urllib2.HTTPCookieProcessor(server.Cookie),\ server.https_handler,
urllib2.HTTPCookieProcessor(server.Cookie),
MultipartPostHandler) MultipartPostHandler)
elif str(server.use_proxy) == "True": elif str(server.use_proxy) == "True":
if str(server.use_proxy_from_os) == "True": if str(server.use_proxy_from_os) == "True":
urlopener = urllib2.build_opener(server.digest_handler,\ urlopener = urllib2.build_opener(server.digest_handler,
server.basic_handler,\ server.basic_handler,
urllib2.HTTPCookieProcessor(server.Cookie),\ server.https_handler,
urllib2.HTTPCookieProcessor(server.Cookie),
MultipartPostHandler) MultipartPostHandler)
else: else:
# if proxy from OS is not used there is to add a authenticated proxy handler # if proxy from OS is not used there is to add a authenticated proxy handler
server.passman.add_password(None, server.proxy_address, server.proxy_username, server.proxy_password) server.passman.add_password(None, server.proxy_address, server.proxy_username, server.proxy_password)
server.proxy_handler = urllib2.ProxyHandler({"http": server.proxy_address, "https": server.proxy_address}) server.proxy_handler = urllib2.ProxyHandler({"http": server.proxy_address, "https": server.proxy_address})
server.proxy_auth_handler = urllib2.ProxyBasicAuthHandler(server.passman) server.proxy_auth_handler = urllib2.ProxyBasicAuthHandler(server.passman)
urlopener = urllib2.build_opener(server.proxy_handler,\ urlopener = urllib2.build_opener(server.proxy_handler,
server.proxy_auth_handler,\ server.proxy_auth_handler,
server.digest_handler,\ server.digest_handler,
server.basic_handler,\ server.basic_handler,
urllib2.HTTPCookieProcessor(server.Cookie),\ server.https_handler,
urllib2.HTTPCookieProcessor(server.Cookie),
MultipartPostHandler) MultipartPostHandler)
return urlopener return urlopener


Expand Down
12 changes: 12 additions & 0 deletions Nagstamon/Nagstamon/Server/Generic.py
Expand Up @@ -30,6 +30,9 @@
import base64 import base64
import re import re
import gobject import gobject
# necessary for Python-2.7.9-ssl-support-fix https://github.com/HenriWahl/Nagstamon/issues/126
if sys.version_info >= (2, 7, 9):
import ssl


# to let Linux distributions use their own BeautifulSoup if existent try importing local BeautifulSoup first # to let Linux distributions use their own BeautifulSoup if existent try importing local BeautifulSoup first
# see https://sourceforge.net/tracker/?func=detail&atid=1101370&aid=3302612&group_id=236865 # see https://sourceforge.net/tracker/?func=detail&atid=1101370&aid=3302612&group_id=236865
Expand Down Expand Up @@ -141,6 +144,15 @@ def __init__(self, **kwds):
self.proxy_handler = None self.proxy_handler = None
self.proxy_auth_handler = None self.proxy_auth_handler = None
self.urlopener = None self.urlopener = None
# necessary for Python-2.7.9-ssl-support-fix https://github.com/HenriWahl/Nagstamon/issues/126
if sys.version_info >= (2, 7, 9):
try:
self.https_handler = urllib2.HTTPSHandler(context=ssl._create_unverified_context())
except:
self.https_handler = urllib2.HTTPSHandler()
else:
self.https_handler = urllib2.HTTPSHandler()

# headers for HTTP requests, might be needed for authorization on Nagios/Icinga Hosts # headers for HTTP requests, might be needed for authorization on Nagios/Icinga Hosts
self.HTTPheaders = dict() self.HTTPheaders = dict()
# attempt to use only one bound list of TreeViewColumns instead of ever increasing one # attempt to use only one bound list of TreeViewColumns instead of ever increasing one
Expand Down

0 comments on commit 1f99d2f

Please sign in to comment.