Python IMAPClient openssl错误Windows 7

时间:2016-08-06 15:35:35

标签: python windows pyopenssl

我正在为一个非常简单的Windows cmd的imap客户端工作。它的工作是搜索具有特定form:地址的消息,并将正文打印到标准输出。

OpenSSL是从here安装的,目录存在于PATH

注意:此脚本在Linux上运行良好。

修改:已经尝试过this解决方案。它没有用。

问题是它会为openssl抛出此异常:

Traceback (most recent call last):
  File "simplemailclient.py", line 21, in <module>
    context = imapclient.create_default_context()
  File "C:\Python27\lib\site-packages\imapclient\tls.py", line 109, in create_de
fault_context
    context.load_verify_locations(cadata=certs)
  File "C:\Python27\lib\site-packages\backports\ssl\core.py", line 654, in load_
verify_locations
    self._ctx.load_verify_locations(cafile, capath)
  File "C:\Python27\lib\site-packages\OpenSSL\SSL.py", line 533, in load_verify_
locations
    _raise_current_error()
  File "C:\Python27\lib\site-packages\OpenSSL\_util.py", line 48, in exception_f
rom_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: []

这是我的代码:

import email
import imapclient
import sys
from backports import ssl


HOST = sys.argv[1]
USERNAME = sys.argv[2]
PASSWORD = sys.argv[3]

context = imapclient.create_default_context()
context.check_hostname = False
context.verify_mode = 0


server = imapclient.IMAPClient(HOST, use_uid=True, ssl=True, ssl_context=context)
server.login(USERNAME, PASSWORD)
select_info = server.select_folder('INBOX')

messages = server.search([u'FROM','user@example.net'])

response = server.fetch(messages, ['RFC822'])

for msgid, data in response.iteritems():
        messageString= data['RFC822']
        msgStringParsed = email.message_from_string(messageString)
        for part in msgStringParsed.walk():
            if part.get_content_type() == "text/plain":
                print part.get_payload()
                exit(0)
            pass

0 个答案:

没有答案