0

我制作了一个 python 脚本来使用 python 和 gmail 发送带有附件的邮件。几个月来它工作得很好,但由于某种原因,我的代码现在给了我一个OSError: [Errno 101] Network is unreachable错误。

这是我正在使用的代码(仅关注电子邮件部分):

from pdf_mail import sendpdf 

send_pdf = sendpdf("Sending gmail address", 
                        "email_receiver", 
                        "###Password###",
                        "e-mail title", 
                        "Body text", 
                        "PDF attachment name", 
                        "Location of PDF file") 

# sending an email 
send_pdf.email_send()

我也确实在这个 Google 帐户上打开了访问不太安全的应用程序DisplayUnlockCaptcha 。在网上找不到解决方案后,我尝试使用不同的 gmail 帐户,但没有给出不同的结果。这是我得到的完整错误:

gitpod /workspace/workspace-name (master) $ python3 -m script_invoices.py
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/workspace/workspace-name/script_invoices.py", line 253, in <module>
    send_pdf.email_send()
  File "/workspace/.pip-modules/lib/python3.8/site-packages/pdf_mail/python.py", line 45, in email_send
    s = smtplib.SMTP('smtp.gmail.com', 587) 
  File "/usr/lib/python3.8/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.8/smtplib.py", line 310, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

有人知道我能做什么吗?

4

0 回答 0