Sunday, November 15, 2015

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581) fix on debian 8

I'm using:

Debian GNU/Linux 8
Python 2.7.9
openssl 1.0.1k-3

Using python (pip) to access https stuff, I got the error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/", line 122, in main
status =, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/", line 40, in run
pypi_hits =, index_url)
File "/usr/lib/python2.7/dist-packages/pip/commands/", line 54, in search
hits ={'name': query, 'summary': query}, 'or')
File "/usr/lib/python2.7/", line 1233, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/", line 1591, in __request
File "/usr/lib/python2.7/", line 1273, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/", line 1301, in single_request
self.send_content(h, request_body)
File "/usr/lib/python2.7/", line 1448, in send_content
File "/usr/lib/python2.7/", line 997, in endheaders
File "/usr/lib/python2.7/", line 850, in _send_output
File "/usr/lib/python2.7/", line 812, in send
File "/usr/lib/python2.7/", line 1212, in connect
File "/usr/lib/python2.7/", line 350, in wrap_socket
File "/usr/lib/python2.7/", line 566, in __init__
File "/usr/lib/python2.7/", line 788, in do_handshake
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

Quick fix (can or cannot work... and not to be permanent as not
verifying the certificates is not very smart)
In your code, do:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Permanent solution

rmdir /usr/local/share/ca-certificates (was blank)
ln -s /usr/share/ca-certificates/mozilla /usr/local/share/ca-certificates
sudo apt-get install ca-certificates # in case you don't have it already
sudo update-ca-certificates

# the new files will be sym-linked here:

That fixed it for me at least.