• 环境: Mac 10.13.6 python3.7

  • 代码

from urllib.request import urlopen
html = urlopen('https://en.wikipedia.org/wiki/Kevin_Bacon',)
  • 报错如下urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) , 大概意思是证书(certificate)验证失败

  • 解决办法:

from urllib.request import urlopen
import ssl
# 导入头文件

# 生成证书上下文(unverified 就是不验证https证书)
context = ssl._create_unverified_context()
# 改为如下即可
html = urlopen('https://en.wikipedia.org/wiki/Kevin_Bacon', context=context)
  • 另外一种解决办法是重写https默认的验证方式:
from urllib.request import urlopen
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
html = urlopen('https://en.wikipedia.org/wiki/Kevin_Bacon',)

以上两种方式选其一即可

这里是requests请求https证书报错解决办法: https://www.cnblogs.com/adampei-bobo/p/9414586.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-10-08
  • 2022-01-18
  • 2022-01-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案