0

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.

Kostas Charitidis
  • 2,991
  • 1
  • 12
  • 23
Ashwani
  • 1,340
  • 1
  • 16
  • 34

1 Answers1

1
 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.

Ashwani
  • 1,340
  • 1
  • 16
  • 34