微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

电子邮件读取 SSL 错误 [SSL: BAD_LENGTH]

如何解决电子邮件读取 SSL 错误 [SSL: BAD_LENGTH]

    context = ssl.create_default_context()
    with MailBox('outlook.office365.com',ssl_context=context).login(email,password) as mailBox:
        email_count = mailBox.folder.status('INBox')['MESSAGES']
        with alive_bar (email_count) as bar:
            for msg in mailBox.fetch(mark_seen=False,headers_only=True,bulk=True): #
                try:
                    count+=1
                except Exception as e:
                    print("***************** ERROR ",e)
                bar()

参考上面的代码,我正在尝试访问该电子邮件,但出现了如下所示的错误。如果我删除“bulk=True”,我的代码就没有问题,但我需要“bulk=True”,所以我的代码不是超级慢。

批量定义(https://github.com/ikvk/imap_tools): bulk = False,False - 每 N 个命令分别获取每条消息 - 内存消耗低,速度慢; True - 每 1 个命令获取所有消息 - 内存消耗高,速度快

我在谷歌上搜索并尝试了所有记录在此的内容,甚至从其他人那里得到了帮助,但没有任何效果。我也试过在 KVM 上遇到同样的问题。

错误

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",line 981,in _command
    self.send(data + CRLF)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",line 323,in send
    self.sock.sendall(data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py",line 1204,in sendall
    v = self.send(byte_view[count:])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py",line 1173,in send
    return self._sslobj.write(data)
brokenPipeError: [Errno 32] broken pipe

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/Users//Desktop/Botach Email List/BotachEmailDB/app.py",line 159,in add_email
    for msg in mailBox.fetch(bulk=True): #
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/imap_tools/mailBox.py",line 105,in fetch
    for fetch_item in (self._fetch_in_bulk if bulk else self._fetch_by_one)(nums,message_parts,reverse):  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/imap_tools/mailBox.py",line 75,in _fetch_in_bulk
    fetch_result = self.Box.fetch(','.join(message_nums),message_parts)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",line 539,in fetch
    typ,dat = self._simple_command(name,message_set,line 1205,in _simple_command
    return self._command_complete(name,self._command(name,*args))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",line 983,in _command
    raise self.abort('socket error: %s' % val)
imaplib.IMAP4.abort: socket error: [Errno 32] broken pipe

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",in send
    return self._sslobj.write(data)
ssl.SSLError: [SSL: BAD_LENGTH] bad length (_ssl.c:2485)

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py",line 2447,in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py",line 1952,in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask_cors/extension.py",line 165,in wrapped_function
    return cors_after_request(app.make_response(f(*args,**kwargs)))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py",line 1821,in handle_user_exception
    reraise(exc_type,exc_value,tb)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/_compat.py",line 39,in reraise
    raise value
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py",line 1950,in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py",line 1936,in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask_monitoringdashboard/core/measurement.py",line 127,in wrapper
    raise raised_exception
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask_monitoringdashboard/core/measurement.py",line 107,in evaluate
    result = route_handler(*args,**kwargs)
  File "/Users//Desktop/Botach Email List/BotachEmailDB/app.py",line 181,in add_email
    count+=1
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/imap_tools/mailBox.py",line 35,in __exit__
    self.logout()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/imap_tools/mailBox.py",line 50,in logout
    result = self.Box.logout()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",line 633,in logout
    typ,dat = self._simple_command('logoUT')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imaplib.py",in _command
    raise self.abort('socket error: %s' % val)
imaplib.IMAP4.abort: socket error: [SSL: BAD_LENGTH] bad length (_ssl.c:2485)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。