Issue
I have a requirement where I need to modify a python warning i.e I need to print a "user-friendly" warning message If I get a warning from the code. I don't want the file name on stdout.
with requests.get(url, stream=True, timeout=300,verify='/etc/ssl/certs/') as r:
I get a warning which prints the file name if the URL is self-signed.
Solution
with warnings.catch_warnings(record=True) as w:
with requests.get(url, stream=True, timeout=300, verify='/etc/ssl/certs/') as r:
if w:
print w[0].message
If there is any warning returned by request.get() then that warning will be available in w[0].message variable and If you want to modify it, you can.
Answered By - Ashwani Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.