Home >Backend Development >Python Tutorial >How to Solve the 'SSL: CERTIFICATE_VERIFY_FAILED' Error in Python's urllib?

How to Solve the 'SSL: CERTIFICATE_VERIFY_FAILED' Error in Python's urllib?

Linda Hamilton
Linda HamiltonOriginal
2024-12-23 21:13:14714browse

How to Solve the

urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error

Error:

Exception in thread Thread-3:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in        __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in  run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Matthew/Desktop/Skypebot 2.0/bot.py", line 271, in process
info = urllib2.urlopen(req).read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>

Issue:

The error is triggered by a failed attempt to establish an HTTPS connection due to a certificate verification issue. The API requires HTTPS, necessitating a bypass of the certificate verification.

Solution for macOS Python 3.6:

This solution is specific to the "SSL: CERTIFICATE_VERIFY_FAILED" error when using Python 3.6 on macOS.

  1. Navigate to /Applications/Python 3.6/ReadMe.rtf.
  2. Install the certifi package using the command:
    /Applications/Python 3.6/Install Certificates.command (Terminal App)

Additional Notes:

  • This solution is not applicable to all "SSL: CERTIFICATE_VERIFY_FAILED" errors.
  • If you encounter this error in other contexts, consult the Python documentation or search for more specific solutions online.

The above is the detailed content of How to Solve the 'SSL: CERTIFICATE_VERIFY_FAILED' Error in Python's urllib?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn