使用imap访问gmail时出现超时错误

时间:2017-08-24 11:35:54

标签: python gmail-imap

当我运行我的python脚本来检查我的Gmail电子邮件时,我在命令行上收到此错误:

 File "testmail.py", line 6, in <module>
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
 File "C:\Users\hp\Anaconda3\lib\imaplib.py", line 1269, in __init__
IMAP4.__init__(self, host, port)
 File "C:\Users\hp\Anaconda3\lib\imaplib.py", line 189, in __init__
self.open(host, port)
 File "C:\Users\hp\Anaconda3\lib\imaplib.py", line 1282, in open
IMAP4.open(self, host, port)
 File "C:\Users\hp\Anaconda3\lib\imaplib.py", line 286, in open
self.sock = self._create_socket()
 File "C:\Users\hp\Anaconda3\lib\imaplib.py", line 1272, in _create_socket
sock = IMAP4._create_socket(self)
 File "C:\Users\hp\Anaconda3\lib\imaplib.py", line 276, in _create_socket
return socket.create_connection((self.host, self.port))
 File "C:\Users\hp\Anaconda3\lib\socket.py", line 711, in create_connection
raise err
 File "C:\Users\hp\Anaconda3\lib\socket.py", line 702, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the     connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我的python脚本是:

import imaplib

USER = 'facereco1.0@gmail.com'
PASSWORD = '**********'

mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
mail.login(USER, PASSWORD)
mail.select('Inbox')

status, data = mail.search(None, 'ALL')
for num in data[0].split():
status, data = mail.fetch(num, '(RFC822)')
print('Message %s\n%s\n' % (num, data[0][1]))

mail.close()

mail.logout()

我正在使用我的宿舍LAN网络。

0 个答案:

没有答案