[PYTHON] What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon

When I run nltk.download (), I get an SSL error like this:

$ python3 -c 'import nltk; nltk.download("all")'
[nltk_data] Error loading all: <urlopen error [SSL:
[nltk_data]     CERTIFICATE_VERIFY_FAILED] certificate verify failed:
[nltk_data]     unable to get local issuer certificate (_ssl.c:1056)>

Save the following with an appropriate file name and execute

import nltk
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    pass
else:
    ssl._create_default_https_context = _create_unverified_https_context

nltk.download()

reference https://stackoverflow.com/a/57954593

Recommended Posts

What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon
What to do when Japanese is not displayed on matplotlib
What to do if pip install mysqlclient fails on MacOS
What to do if "export" keeps appearing on terminal when trying to put Python on macOS
What to do if the inode is exhausted on EC2 Linux
What to do if an error occurs when importing numpy with VScode
What to do when PermissionError of tempfile.mkstemp occurs
What to do if abort is displayed when inputting camera video in OpenCV
What to do if Japanese language support is not completely installed on Ubuntu 16.04
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
curl: (60) What to do when Issuer certificate is invalid.
What to do if SciPy installation fails on CentOS
What to do if a UnicodeDecodeError occurs in pip
What to do if pyenv is not enabled (zsh)
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do if Python IntelliSense is not displayed in VS Code on Windows
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do when PyCharm font is strange or garbled
What to do when a Remove Error occurs when updating conda
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do when an error occurs with import _ssl
What to do if package installation fails when deploying to heroku
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
What to do if `pip install matplotlib` fails on Mac
What to do if you can't use WiFi on Linux
What to do when a Missing artifact occurs in a jar that is not defined in pom.xml
What to do if you get an Undefined error:'Module_six_moves_urllib_parse' object has no attribute'urlencode' on MacOS
What to do when no display name occurs when unittesting Python + Tkinter on Github Actions Memo
What to do if ʻObject arrays cannot be loaded when allow_pickle = False` occurs in numpy.load ()
What to do if yum breaks
What to do if Python doesn't work on Git for Windows
[Beanstalk] What to do when an error occurs with import uuid
What to do if Insecure Platform Warning appears when running Python
What to do if "Unnamed: 0" is added in to_csv-> read_csv in pandas
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do when UnicodeDecodeError occurs during read_csv in pandas (pd.read_table ())
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do when the value type is ambiguous in Python?
What to do if grep: empty (sub) expression appears on Mac grep
[virtualbox] What to do when [Could not retrieve mirrorlist] appears when yum update is performed on CentOS7
What to do if you get angry if you don't have libxml / xmlversion.h when installing lxml on CentOS
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
What to do if there is a decimal in python json .dumps
What to do if you get the message "" ~ .pkg "is corrupted and cannot be opened" when installing wxPython on Mac OS X
What to do if the Pipenv environment is corrupted by updating Homebrew
What to do if you forget your login password on Manjaro Linux
What to do if you get stuck during Anaconda installation on Linux
[Python] What to do when an error related to SSL authentication is returned
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
What to do if you get an error when trying to load mnist
What to do if you get a Permission denied (public key) error when trying to pull on Github
What to do in my case when pyenv install is not possible after upgrading to macOS Big Sur
What to do if fprintd requires a password when registering your fingerprint
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
Notes on what to do when matplotlib scatter () / scatter3d () does not work
What to do if you get an error when installing Dlib (Ubuntu)
[OSX] [pyenv] What to do when an SSL error occurs in pip
What to do when a warning message is displayed in pip list
What to do if an error occurs when loading a python project created with poetry into VS Code
Notes on what to do if "macOS 11 or later required!" Appears in Big Sur or pyarrow2.0.0 cannot be installed