Browse Source

Merge "Add SubjectAltNameWarning and a helper function"

Jenkins 3 years ago
parent
commit
40126a4040
1 changed files with 19 additions and 0 deletions
  1. 19
    0
      requestsexceptions/__init__.py

+ 19
- 0
requestsexceptions/__init__.py View File

@@ -12,6 +12,8 @@
12 12
 # License for the specific language governing permissions and limitations
13 13
 # under the License.
14 14
 
15
+import warnings
16
+
15 17
 try:
16 18
     from requests.packages.urllib3.exceptions import InsecurePlatformWarning
17 19
 except ImportError:
@@ -27,3 +29,20 @@ except ImportError:
27 29
         from urllib3.exceptions import InsecureRequestWarning
28 30
     except ImportError:
29 31
         InsecureRequestWarning = None
32
+
33
+try:
34
+        from requests.packages.urllib3.exceptions import SubjectAltNameWarning
35
+except ImportError:
36
+    try:
37
+        from urllib3.exceptions import SubjectAltNameWarning
38
+    except ImportError:
39
+        SubjectAltNameWarning = None
40
+
41
+
42
+def squelch_warnings(insecure_requests=True):
43
+    if SubjectAltNameWarning:
44
+        warnings.filterwarnings('ignore', category=SubjectAltNameWarning)
45
+    if InsecurePlatformWarning:
46
+        warnings.filterwarnings('ignore', category=InsecurePlatformWarning)
47
+    if insecure_requests and InsecureRequestWarning):
48
+        warnings.filterwarnings('ignore', category=InsecureRequestWarning)

Loading…
Cancel
Save