[Python] What to do when an error related to SSL authentication is returned

** Problem **: I got the following error when scraping with Python.

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

** Status **: * https * request with * UserAgent * in the header in module * urllib.request *.

** Problem **: An error that occurred when * SSL * was used as one of the encryption methods in * https * communication. SSL is an encryption method that allows you to confirm the identity of the company that operates the website by placing an electronic certificate called an "SSL server certificate" on the web server and verifying it when connecting. In addition, the SSL server certificate itself must pass the authentication work of the operator by the "certificate authority" that is authorized to issue, and conversely, if the SSL server certificate of the untrusted issuer is used, the Web browser A warning screen is displayed at. As a result, an SSL error like this one may be displayed.

** Solution **: Add the following.


import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Please note that it is not safe in terms of security.

Recommended Posts

[Python] What to do when an error related to SSL authentication is returned
What to do when an error occurs with import _ssl
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
[OSX] [pyenv] What to do when an SSL error occurs in pip
[python] What to do when an error occurs in send_keys of headless chrome
What to do if you get an error when installing python with pyenv
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
What to do if you get an error when importing matplotlib in Python (Mac)
What to do when the value type is ambiguous in Python?
[What is an algorithm? Introduction to Search Algorithm] ~ Python ~
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
What to do when psycopg2 throws an error when pipenv lock under Pipenv environment
How to write what to do when an application is first displayed in Qt for Python with Designer
What to do if PyInstaller3.5 gives an error in Python3.8 (TypeError: an integer is required (got type bytes))
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
What to do when "cannot import name xxx" [Python]
What to do when you can't bind CaboCha to Python
What to do if an error occurs when loading a python project created with poetry into VS Code
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you run python in IntelliJ and end with an error
What to do when Japanese is not displayed on matplotlib
What to do when PyCharm font is strange or garbled
What to do when Ubuntu crashes
What to do when you get an error saying "Name resolution temporarily failed" on linux
What to do when there is no response due to Proxy setting in Python web scraping
What to do with PYTHON release?
Python> What is an extended slice?
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if Insecure Platform Warning appears when running Python
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
NameError: global name'dot_parser' is not defined and what to do when it comes up in python
What to do if there is a decimal in python json .dumps
What to do when the result downloaded via scrapy is in English
What to do when pyinstaller: error: argument --add-binary: invalid add_data_or_binary value: appears
[Docker] What to do when error Couldn't find the binary git appears
How to deal with SSL error when connecting to S3 with boto of Python
What to do if pyenv install does not proceed with an error
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
What to do when a warning message is displayed in pip list
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
[Mac OS] What to do when Python is not installed as a framework. Is displayed when import matplotlib is performed.
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
What to do if an error occurs in TensorFlow RNN related import or RNN (LSTM) Cell (v 0.11r ~)
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
[Python] I want to know the variables in the function when an error occurs!
What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon
[Python] What I did to do Unit Test
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What is python
What to do when PermissionError of tempfile.mkstemp occurs
[Python] What to check when you get a Unicode Decode Error in Django
What to do if abort is displayed when inputting camera video in OpenCV