gpt4 book ai didi

python - 连接重置错误: [WinError 10054] An existing connection was forcibly closed by the remote host (while accessing Gmail emails)

转载 作者:行者123 更新时间:2023-12-01 08:56:04 26 4
gpt4 key购买 nike

当我尝试使用 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')

最佳答案

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

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

关于python - 连接重置错误: [WinError 10054] An existing connection was forcibly closed by the remote host (while accessing Gmail emails),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52759754/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com