天天看點

Python通路https報錯CERTIFICATE_VERIFY_FAILED

在Mac上安裝了Python 3.6版本,使用urllib庫通路網頁卻傳回了

這樣的錯誤。

這是由于MacOS版本的python 3.6版本沒有使用系統的openssl進行證書驗證。在

/Applications/Python\ 3.6/

目錄下可以找到Readme.rtf檔案,其中說明到:

NEW This variant of Python 3.6 now includes its own private copy of OpenSSL 1.0.2. Unlike previous releases, the deprecated Apple-supplied OpenSSL libraries are no longer used. This also means that the trust certificates in system and user keychains managed by the Keychain Access application and the security command line utility are no longer used as defaults by the Python ssl module.

解決方法是運作

/Applications/Python\ 3.6/Install\ Certificates.command

指令,安裝certifi子產品即可。

可見stackoverflow上的文章:

urllib and “SSL: CERTIFICATE_VERIFY_FAILED” Error