I am trying to get data from the web using python. I imported urllib.request package for it but while executing, I get error:
certificate verify failed: unab
Paste the following code at the start:
# paste this at the start of code
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
I had the error with conda on linux. My solution was simple.
conda install -c conda-forge certifi
I had to use the conda forge since the default certifi appears to have problems.
For those who this problem persists: - Python 3.6 (some other versions too?) on MacOS comes with its own private copy of OpenSSL. That means the trust certificates in the system are no longer used as defaults by the Python ssl module. To fix that, you need to install a certifi package in your system.
You may try to do it in two ways:
1) Via PIP:
pip install --upgrade certifi
2) If it doesn't work, try to run a Cerificates.command that comes bundled with Python 3.6 for Mac:
open /Applications/Python\ 3.6/Install\ Certificates.command
One way or another, you should now have certificates installed, and Python should be able to connect via HTTPS without any issues.
Hope this helped.
For anyone who still wonders on how to fix this, i got mine by installing the "Install Certificates.command
"
Here is how I did,
Just double click on that file wait for it to install and in my case, you will be ready to go