Add SubjectAltNameWarning and a helper function

shade hits the SubjectAltName problem when talking to Rackspace. Also,
one of the things you want to do is turn off the warnings - so add a
function for that.

Change-Id: I3a55c66e5a4033a47a9d8704dd30709a5c53edc9
This commit is contained in:
Monty Taylor 2015-11-03 12:17:16 -05:00
parent 82fb34c4e9
commit 448d469780
1 changed files with 19 additions and 0 deletions

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import warnings
try:
from requests.packages.urllib3.exceptions import InsecurePlatformWarning
except ImportError:
@ -27,3 +29,20 @@ except ImportError:
from urllib3.exceptions import InsecureRequestWarning
except ImportError:
InsecureRequestWarning = None
try:
from requests.packages.urllib3.exceptions import SubjectAltNameWarning
except ImportError:
try:
from urllib3.exceptions import SubjectAltNameWarning
except ImportError:
SubjectAltNameWarning = None
def squelch_warnings(insecure_requests=True):
if SubjectAltNameWarning:
warnings.filterwarnings('ignore', category=SubjectAltNameWarning)
if InsecurePlatformWarning:
warnings.filterwarnings('ignore', category=InsecurePlatformWarning)
if insecure_requests and InsecureRequestWarning):
warnings.filterwarnings('ignore', category=InsecureRequestWarning)