【问题标题】:Error while sending email with SMTP and Gmail. certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)使用 SMTP 和 Gmail 发送电子邮件时出错。证书验证失败:无法获取本地颁发者证书 (_ssl.c:1108)
【发布时间】:2021-12-27 02:29:29
【问题描述】:

我使用 Python smtplib 通过 gmail 发送电子邮件。但是,当我运行以下代码时:

import ssl
import smtplib
context = ssl.create_default_context()
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls(context=context)

我在server.starttls(context=context) 行收到错误消息。我收到的错误如下:

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

我正在使用Windows 系统。通过浏览各种论坛帖子,我尝试了几种不同的方法。但是,没有任何效果。我也试过了

pip uninstall certifi
pip install certifi

论坛上的常见回复是运行Certificates.command 或类似的东西。但是,我在 Windows 上找不到该文件。我正在运行python 3.8.2

【问题讨论】:

    标签: python python-3.x smtp gmail


    【解决方案1】:
    1. 将 pip 升级到最新版本:

      python -m pip install --upgrade pip
      
    2. 升级certifi 包:

      pip install certifi --upgrade
      

    我确实尝试升级 certifi,但升级 pip 是必要的先决条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-12
      • 2021-09-17
      • 1970-01-01
      • 2021-11-25
      • 2020-12-13
      • 1970-01-01
      • 2019-03-19
      相关资源
      最近更新 更多