Search code examples
pythonpython-2.7urllib2

Hide UserWarning from urllib2



I use an opener with password manager and when I use my opener for the first time I've hot the following warning message :

/usr/lib/python2.7/urllib2.py:894: UserWarning: Basic Auth Realm was unquoted
  url, req, headers)

My app seems to work fine, but how can I hide this message ?

PS: I use :

Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2

Solution

  • Use the warnings module to filter out specific warnings in your code:

    import warnings
    
    warnings.filterwarnings("ignore", category=UserWarning, module='urllib2')