I have a portion of my code where I knowingly make an Insecure Request. So I disable warnings with
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
After that part, how do I reenable/reset urllib3
warnings in my script?
I have a portion of my code where I knowingly make an Insecure Request. So I disable warnings with
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
After that part, how do I reenable/reset urllib3
warnings in my script?
If you need to programmatically reset all warnings, you can do:
import warnings
warnings.resetwarnings()
This will cause all of the urllib3 warnings (and all other warnings) to revert back to the default state.
The urllib3.disable_warnings
helper is a one-line wrapper around warnings.simplefilter('ignore', category)
.
If you'd like to apply a specific category override yourself, you can do something like:
warnings.simplefilter('default', category)
More on warning filters here: https://docs.python.org/2/library/warnings.html#available-functions
The warnings
module has a documentation section on temporarily ignoring warnings. If you have one part of your code where you're making the insecure request, you can wrap that in a context:
import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore', urllib3.exceptions.InsecureRequestWarning)
# Run the rest of your code
© 2022 - 2024 — McMap. All rights reserved.