@@ -233,8 +233,13 @@ def __init__(self, hostname,
233233 # If certificate path hasn't been specified in either environment
234234 # variable, replace the default adapter with one that will use the
235235 # 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 )
238243
239244 self .filters = DEFAULT_FILTERS
240245
@@ -541,22 +546,13 @@ def __enter__(self):
541546 self ._old_session = _session
542547 _session = self
543548
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-
550549 return self
551550
552551 def __exit__ (self , exc_type , exc_val , exc_tb ):
553552 # Restore previous current session
554553 global _session
555554 _session = self ._old_session
556555
557- # Restore warning levels
558- self ._filter_context .__exit__ ()
559-
560556 super (Session , self ).__exit__ ()
561557
562558
0 commit comments