Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 697
Zulu Avatar asked May 17 '26 21:05

Zulu


1 Answers

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

import warnings

warnings.filterwarnings("ignore", category=UserWarning, module='urllib2')
like image 57
Martijn Pieters Avatar answered May 19 '26 10:05

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!