Posted on

Question :


I apologize if this is a silly question, but I have been trying to teach myself how to use BeautifulSoup so that I can create a few projects.

I was following this link as a tutorial:

After following the exact same code as him, this is the error that I get:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 1240, in do_open
    h.request(req.get_method(), req.selector,, headers)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/", line 1083, in request
    self._send_request(method, url, body, headers)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/", line 1128, in _send_request
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/", line 1079, in endheaders
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/", line 911, in _send_output
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/", line 854, in send
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/", line 1237, in connect
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/", line 376, in wrap_socket
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/", line 747, in __init__
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/", line 983, in do_handshake
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/", line 628, in do_handshake
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 3, in <module>
    x = urllib.request.urlopen('')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 162, in urlopen
    return, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 465, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 483, in _open
'_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 443, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 1283, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/", line 1242, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED]     certificate verify failed (_ssl.c:645)>

Can someone help me figure out how to fix this?

Answer #1:

In my case, I used the ssl module to “workaround” the certification like so:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

Then to read your link content, you can use:

Answered By: Jia

Answer #2:

Go to the folder where Python is installed, e.g., in my case (Mac OS) it is installed in the Applications folder with the folder name ‘Python 3.6’. Now double click on ‘Install Certificates.command’. You will no longer face this error.

For those not running a mac, or having a different setup and can’t find this file, the file merely runs:

pip install --upgrade certifi

Hope that helps someone 🙂

Answered By: Bhavik

Answer #3:

On Debian 9 I had to:

$ sudo update-ca-certificates --fresh
$ export SSL_CERT_DIR=/etc/ssl/certs

I’m not sure why, but this enviroment variable was never set.

Answered By: Dan Walters

Answer #4:

When you are using a self signed cert urllib3 version 1.25.3 refuses to ignore the SSL cert

To fix remove urllib3-1.25.3 and install urllib3-1.24.3

pip3 uninstall urllib3

pip3 install urllib3==1.24.3

Tested on Linux MacOS and Window$

Answered By: AAber

Answer #5:

I had this problem in MacOS, and I solved it by linking the brew installed python 3 version, with

brew link python3

After that, it worked without a problem.

Answered By: Kostas Tsiligkiris

Answer #6:

I have a lib what use what use but I have a custom CA included in my /etc/ssl/certs.

So I solved my problem like this:

# Your TLS certificates directory (Debian like)
export SSL_CERT_DIR=/etc/ssl/certs
# CA bundle PATH (Debian like again)
export CA_BUNDLE_PATH="${SSL_CERT_DIR}/ca-certificates.crt"
# If you have a virtualenv:
. ./.venv/bin/activate
# Get the current certifi CA bundle
CERTFI_PATH=`python -c 'import certifi; print(certifi.where())'`


Et voilà !

Answered By: Nicolas Ledez

Leave a Reply

Your email address will not be published. Required fields are marked *