【问题标题】:ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host (while accessing Gmail emails)ConnectionResetError: [WinError 10054] 远程主机强制关闭现有连接(访问 Gmail 电子邮件时)
【发布时间】:2023-03-26 04:55:02
【问题描述】:

当我尝试使用 python 的 imap-tools 模块访问我的 gmail 电子邮件时,出现标题错误。以下是建立连接时给出的详细信息。

    Traceback (most recent call last):
  File "d:\PythonLabs\delete_gmail_emails.py", line 3, in <module>
    gautham_gmail_box = MailBox('imap.gmail.com')
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\site-packages\imap_tools\main.py", line 61, in __init__
    host, port or imaplib.IMAP4_SSL_PORT, keyfile, certfile, ssl_context)
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 1283, in __init__
    IMAP4.__init__(self, host, port)
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 197, in __init__
    self.open(host, port)
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 1296, in open
    IMAP4.open(self, host, port)
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 294, in open
    self.sock = self._create_socket()
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 1288, in _create_socket
    server_hostname=self.host)
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 850, in _create
    self.do_handshake()
  File "C:\Users\skolluru\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1108, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

[Done] exited with code=1 in 0.338 seconds

我认为错误是因为我的 gmail 电子邮件使用两步验证进行了保护。我想保持我的 gmail 帐户的安全性,我想知道一种解决方法来从我的 python 程序访问我的电子邮件。

这是我的python代码:

    from imap_tools import MailBox

gautham_gmail_box = MailBox('imap.gmail.com')
gautham_gmail_box.login('my_email@gmail.com','my_password')

【问题讨论】:

    标签: python gmail imap


    【解决方案1】:

    我认为您必须先启用对 Gmail 的一些不安全访问,然后才能以这种方式访问​​它,但我不确定。

    IMO,您最好使用 Google 的官方库通过 Python 访问 Gmail。访问https://developers.google.com/gmail/api/quickstart/python了解更多信息。

    【讨论】:

      猜你喜欢
      • 2020-04-20
      • 2018-01-02
      • 2016-10-20
      • 2019-08-21
      • 2015-02-28
      • 2015-05-24
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      相关资源
      最近更新 更多