Skip to content

Commit 69115de

Browse files
authored
Merge pull request #40 from ChannelFinder/optional_verify_ssl
Optionally verify ssl
2 parents 2d601bb + 3f80ff6 commit 69115de

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

channelfinder/ChannelFinderClient.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from requests import auth
1313
from requests.adapters import HTTPAdapter
1414
from requests.exceptions import HTTPError
15+
import urllib3
1516
from copy import copy
1617

1718
try:
@@ -28,7 +29,7 @@ class ChannelFinderClient(object):
2829
__propertiesResource = "/resources/properties"
2930
__tagsResource = "/resources/tags"
3031

31-
def __init__(self, BaseURL=None, username=None, password=None):
32+
def __init__(self, BaseURL=None, username=None, password=None, verify_ssl=True):
3233
"""
3334
Channel finder client object. It provides a connection object to perform the following operations:
3435
- find: find all channels satisfying given searching criteria
@@ -40,15 +41,22 @@ def __init__(self, BaseURL=None, username=None, password=None):
4041
:param username: user name authorized by channel finder service
4142
:param password: password for the authorized user
4243
"""
43-
self.__baseURL = self.__getDefaultConfig("BaseURL", BaseURL)
44-
self.__userName = self.__getDefaultConfig("username", username)
45-
self.__password = self.__getDefaultConfig("password", password)
46-
if self.__userName and self.__password:
47-
self.__auth = auth.HTTPBasicAuth(self.__userName, self.__password)
48-
else:
49-
self.__auth = None
50-
self.__session = requests.Session()
51-
self.__session.mount(self.__baseURL, HTTPAdapter())
44+
try:
45+
self.__baseURL = self.__getDefaultConfig("BaseURL", BaseURL)
46+
self.__userName = self.__getDefaultConfig("username", username)
47+
self.__password = self.__getDefaultConfig("password", password)
48+
self.__verify_ssl = self.__getDefaultConfig("verify_ssl", verify_ssl)
49+
if self.__userName and self.__password:
50+
self.__auth = auth.HTTPBasicAuth(self.__userName, self.__password)
51+
else:
52+
self.__auth = None
53+
self.__session = requests.Session()
54+
self.__session.mount(self.__baseURL, HTTPAdapter())
55+
self.__session.verify = self.__verify_ssl
56+
if not self.__session.verify:
57+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
58+
except Exception as e:
59+
raise RuntimeError("Error creating ChannelFinderClient: " + str(e))
5260

5361
def __getDefaultConfig(self, key, ref):
5462
"""

0 commit comments

Comments
 (0)