From 448d4697803ad6993d81ca556a63977f1c039a7f Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 3 Nov 2015 12:17:16 -0500 Subject: [PATCH] Add SubjectAltNameWarning and a helper function shade hits the SubjectAltName problem when talking to Rackspace. Also, one of the things you want to do is turn off the warnings - so add a function for that. Change-Id: I3a55c66e5a4033a47a9d8704dd30709a5c53edc9 --- requestsexceptions/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/requestsexceptions/__init__.py b/requestsexceptions/__init__.py index aefb002..f1c1e50 100644 --- a/requestsexceptions/__init__.py +++ b/requestsexceptions/__init__.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import warnings + try: from requests.packages.urllib3.exceptions import InsecurePlatformWarning except ImportError: @@ -27,3 +29,20 @@ except ImportError: from urllib3.exceptions import InsecureRequestWarning except ImportError: InsecureRequestWarning = None + +try: + from requests.packages.urllib3.exceptions import SubjectAltNameWarning +except ImportError: + try: + from urllib3.exceptions import SubjectAltNameWarning + except ImportError: + SubjectAltNameWarning = None + + +def squelch_warnings(insecure_requests=True): + if SubjectAltNameWarning: + warnings.filterwarnings('ignore', category=SubjectAltNameWarning) + if InsecurePlatformWarning: + warnings.filterwarnings('ignore', category=InsecurePlatformWarning) + if insecure_requests and InsecureRequestWarning): + warnings.filterwarnings('ignore', category=InsecureRequestWarning)