from:http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error
If you just want to bypass verification, you can create a new SSLContext. By default newly created contexts use CERT_NONE.
Be carefull with this as stated in section 17.3.7.2.1
When calling the SSLContext constructor directly, CERT_NONE is the default. Since it does not authenticate the other peer, it can be insecure, especially in client mode where most of time you would like to ensure the authenticity of the server you’re talking to. Therefore, when in client mode, it is highly recommended to use CERT_REQUIRED.
But if you just want it to work now for some other reason you can do the following, you’ll have to import ssl
as well:
1 2 3 4 5 6 | input = input.replace("!web ", "") url = "https://domainsearch.p.mashape.com/index.php?name=" + input req = urllib2.Request(url, headers={ 'X-Mashape-Key': 'U3sk6nAZzBmshyiHEUZHigodYxLGp1ZTnkd8LWULJmRRp' }) gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1) # Only for gangstars info = urllib2.urlopen(req, context=gcontext).read() Message.Chat.SendMessage ("" + info) |
This should get round your problem but you’re not really solving any of the issues, but you won’t see the [SSL: CERTIFICATE_VERIFY_FAILED]
because you now aren’t verifying the cert!
To add to the above, if you want to know more about why you are seeing these issues you will want to have a look at PEP 476.
This PEP proposes to enable verification of X509 certificate signatures, as well as hostname verification for Python’s HTTP clients by default, subject to opt-out on a per-call basis. This change would be applied to Python 2.7, Python 3.4, and Python 3.5.
There is an advised opt out which isn’t dissimilar to my advice above:
1 2 3 4 5 | import ssl # This restores the same behavior as before. context = ssl._create_unverified_context() urllib.urlopen("https://no-valid-cert", context=context) |
It also features a highly discouraged option via monkeypatching which you don’t often see in python:
1 2 3 | import ssl ssl._create_default_https_context = ssl._create_unverified_context |
Which overrides the default function for context creation with the function to create an unverified context. This highly discouraged option can be seen in the wild here!