PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] How can I modify python warnings?

 April 28, 2022     python, python-2.7, warnings     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing