Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Disable warnings for SecurityWarning: Certificate has no `subjectAltName`, RFC 2818

Tags:

python

I'm trying to suppress the below warning:

/usr/lib/python2.7/site-packages/urllib3/connection.py:251: SecurityWarning: Certificate has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
  SecurityWarning

my code is as follows

import requests
from orionsdk import SwisClient

#solarwinds creds
hostname = 'SolarWinds-Orion'
username = 'api'
password = 'XXXX'
v_path = '/var/www/itapp/tools/solarwinds.pem'

sites = SiteData.objects.exclude(site_type='Major Site').filter(is_live=True)
swis = SwisClient(hostname, username, password, verify=v_path)

query = """
    SELECT NodeID
          ,NodeName
          ,IPAddress
    FROM Orion.Nodes 
    WHERE NodeName LIKE '%NVR'
"""
requests.packages.urllib3.disable_warnings()
existing_results = swis.query(query)
nodes = existing_results["results"]

My searching shows that if I issue requests.packages.urllib3.disable_warnings(), then the warnings should be suppressed, but no matter where I put that line i always get the warning. Am I missing something or do i need to use something else?

Thanks

like image 506
AlexW Avatar asked Mar 16 '17 16:03

AlexW


1 Answers

Hmm, if i am not mistaken requests uses its own vendored copy of urllib3 but the warning you are getting comes directly from your installed copy of urllib3.

Try doing:

import urllib3
urllib3.disable_warnings(urllib3.exceptions.SecurityWarning)

You can also handle any kind of warning generated by the warnings python library like this:

import warnings
warnings.simplefilter('ignore', urllib3.exceptions.SecurityWarning)
like image 84
Giannis Spiliopoulos Avatar answered Oct 01 '22 16:10

Giannis Spiliopoulos