Python urllib.error.URLError

urllib.erro.URLError

错误信息

urllib.error.URLError:

由字面可知该错误是由于无法进行SSL验证所致

解决方法

查阅Python3.6的版本信息可知Mac二进制版本忽略了对SSL证书的验证,原文1如下:

macOS users: If you are using the Python 3.6 from the python.org binary installer linked on this page, please carefully read the Important Information displayed during installation; this information is also available after installation by clicking on /Applications/Python 3.6/ReadMe.rtf. There is important information there about changes in the 3.6.0 installer-supplied Python, particularly with regard to SSL certificate validation.

在路径 /Applications/Python 3.6 下的 ReadMe.rft 中提到:

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. For 3.6.0, a sample command script is included in /Applications/Python 3.6 to install a curated bundle of default root certificates from the third-party certifi package (https://pypi.python.org/pypi/certifi). If you choose to use certifi, you should consider subscribing to the project's email update service to be notified when the certificate bundle is updated.

与之前的版本不同,该版本不再使用苹果提供的OpenSSL库,用户可选择第三方的certifi包:

  • 目录 /Applications/Python 3.6提供了安装脚本 Install Certificates.command ,直接运行脚本即可。
  • 或使用命令pip3 install certi进行安装

你可能感兴趣的:(Python urllib.error.URLError)