Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL: CERTIFICATE_VERIFY_FAILED with Python3

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: https://www.youtube.com/watch?v=5GzVNi0oTxQ

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/request.py", line 1240, in do_open     h.request(req.get_method(), req.selector, req.data, headers)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1083, in request     self._send_request(method, url, body, headers)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1128, in _send_request     self.endheaders(body)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1079, in endheaders self._send_output(message_body)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 911, in _send_output     self.send(msg)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 854, in send     self.connect()   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1237, in connect server_hostname=server_hostname)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 376, in wrap_socket _context=self)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 747, in __init__ self.do_handshake()   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 983, in do_handshake     self._sslobj.do_handshake()   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 628, in do_handshake     self._sslobj.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 "WorldCup.py", line 3, in <module>     x = urllib.request.urlopen('https://www.google.com')   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 162, in urlopen     return opener.open(url, data, timeout)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 465, in open     response = self._open(req, data)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 483, in _open '_open', req)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 443, in _call_chain     result = func(*args)   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", 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/request.py", 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?

like image 841
PafflesWancakes Avatar asked Feb 23 '16 04:02

PafflesWancakes


People also ask

What does SSL Certificate_verify_failed mean?

SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates. If you're a website owner and you're receiving this error, it could be because you're not using a valid SSL certificate.

How do I run Python 3.6 install certificates commands?

Type cmd in the search bar and hit Enter to open the command line. Type python3 -m pip install certifi in the command line and hit Enter again. This installs certifi for your default Python installation.

Can't connect to HTTPS URL because the SSL module is not available python3?

To Solve Caused by SSLError(“Can't connect to HTTPS URL because the SSL module is not available.”) Error If you are using anaconda then Then add this to PATH variable <path>\Anaconda3 <path>\Anaconda3\scripts <path>\Anaconda3\Library\bin Second Solution is Just copy this file libcrypto-1_1-x64. * libssl-1_1-x64.


1 Answers

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:

urllib.request.urlopen(urllink) 
like image 156
Jia Avatar answered Sep 22 '22 09:09

Jia