Skip to content

Commit 501368e

Browse files
committed
fixed warning supression
1 parent 3c790c0 commit 501368e

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ Unreleased
66
Imports of services in the format `import sasctl.services.model_management as mm` must be
77
changed to `from sasctl.services import model_management as mm`.
88
- `host` and `user` parameters of `Session` renamed to `hostname` and `username` to align with SWAT.
9+
- Only `InsecureRequestWarning` is suppred instead of all `HTTPWarning`
910

1011
**Improvements**
1112
- Added `copy_analytic_store` method to `model_repository` service
12-
- `AuthenticationError` returned instead of `HTTPError` if session authentication fails.
13+
- `AuthenticationError` returned instead of `HTTPError` if session authentication fails.
1314

1415

1516
v0.9.7 (2019-07-18)

src/sasctl/core.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)