@@ -233,8 +233,13 @@ def __init__(self, hostname,
233
233
# If certificate path hasn't been specified in either environment
234
234
# variable, replace the default adapter with one that will use the
235
235
# machine's default SSL _settings.
236
- if 'REQUESTS_CA_BUNDLE' not in os .environ and verify_ssl :
237
- self .mount ('https://' , SSLContextAdapter ())
236
+ if 'REQUESTS_CA_BUNDLE' not in os .environ :
237
+ if verify_ssl :
238
+ self .mount ('https://' , SSLContextAdapter ())
239
+ else :
240
+ # Every request will generate an InsecureRequestWarning
241
+ from urllib3 .exceptions import InsecureRequestWarning
242
+ warnings .simplefilter ('default' , InsecureRequestWarning )
238
243
239
244
self .filters = DEFAULT_FILTERS
240
245
@@ -541,22 +546,13 @@ def __enter__(self):
541
546
self ._old_session = _session
542
547
_session = self
543
548
544
- # Reduce verbosity of warnings. By default, HTTP warnings on thrown on every request
545
- self ._filter_context = warnings .catch_warnings ()
546
- self ._filter_context .__enter__ ()
547
- from urllib3 .exceptions import HTTPWarning
548
- warnings .simplefilter ('once' , HTTPWarning )
549
-
550
549
return self
551
550
552
551
def __exit__ (self , exc_type , exc_val , exc_tb ):
553
552
# Restore previous current session
554
553
global _session
555
554
_session = self ._old_session
556
555
557
- # Restore warning levels
558
- self ._filter_context .__exit__ ()
559
-
560
556
super (Session , self ).__exit__ ()
561
557
562
558
0 commit comments