0

我尝试调用 imapclient.IMAPClient() 函数来创建 IMAPClient 对象。

代码是这样的:

import imapclient
imapObj = imapclient.IMAPClient('imap.gmail.com', ssl=True)

print('Enter your mail adress')
mail = input()

print('Enter your password')
password = input()

imapObj.login(' mail ', ' password ')

错误:

Traceback (most recent call last):
  File "C:\Users\Purgoufr\Documents\Eclipse Projects\Python\Email_and_Text_Message\IMAP_basic_codes.py", line 21, in <module>
    imapObj = imapclient.IMAPClient('imap.gmail.com', ssl=True)
  File "C:\Users\Purgoufr\AppData\Local\Programs\Python\Python35-32\Lib\imapclient\imapclient.py", line 152, in __init__
    self._imap = self._create_IMAP4()
  File "C:\Users\Purgoufr\AppData\Local\Programs\Python\Python35-32\Lib\imapclient\imapclient.py", line 164, in _create_IMAP4
    self._timeout)
  File "C:\Users\Purgoufr\AppData\Local\Programs\Python\Python35-32\Lib\imapclient\tls.py", line 209, in __init__
    imaplib.IMAP4.__init__(self, host, port)
  File "C:\Users\Purgoufr\AppData\Local\Programs\Python\Python35-32\Lib\imaplib.py", line 189, in __init__
    self.open(host, port)
  File "C:\Users\Purgoufr\AppData\Local\Programs\Python\Python35-32\Lib\imapclient\tls.py", line 215, in open
    self.sock = wrap_socket(sock, self.ssl_context, host)
  File "C:\Users\Purgoufr\AppData\Local\Programs\Python\Python35-32\Lib\imapclient\tls.py", line 34, in <lambda>
    context.wrap_socket(sock, server_hostname = host)
AttributeError: 'NoneType' object has no attribute 'wrap_socket'
4

1 回答 1

0

我找到了解决方案。删除以下代码:

print('Enter your mail adress')
mail = input()

print('Enter your password')
password = input()

imapObj.login(' mail ', ' password ')

编写以下代码:

print('Enter your mail adress')
mail = input()
print(mail)

print('Enter your password')
password = input()
print(password)
imapObj.login(mail, password)
于 2017-01-09T15:15:29.077 回答