重复的 SSLEOFError 处理

Reoccuring SSLEOFError handling

我有一个 python 服务器使用 web.py 与经常遇到 SSLEOFError 的 Apple 推送通知服务器通信。我试图处理这个错误,但我似乎无法在 ssl 模块或 pyopenssl 或 _ssl 中找到它。任何帮助处理此错误或可能防止它的帮助将不胜感激。这是堆栈跟踪:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 239, in process
    return self.handle()
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 420, in _delegate
    return handle_class(cls)
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 396, in handle_class
return tocall(*args)
  File "/home/ubuntu/mdm-server/server/API/api.py", line 189, in GET
    COMMAND_QUEUE.get_queue(sql)
  File "/home/ubuntu/mdm-server/server/queue.py", line 165, in get_queue
    self.send_apns(row['udid'], sql)
  File "/home/ubuntu/mdm-server/server/queue.py", line 219, in send_apns
    except ssl.SSLEOFError:
AttributeError: 'module' object has no attribute 'SSLEOFError'

编辑:这是没有错误处理的堆栈跟踪。我现在意识到我可能应该只处理超级 class ssl.SSLERROR 而不是 ssl.SSLEOFERROR 我会尝试这样做,但是如果能深入了解为什么会发生这种情况,我们将不胜感激.

Unexpected error: <class 'ssl.SSLError'>
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 239, in process
    return self.handle()
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 420, in _delegate
    return handle_class(cls)
  File "/usr/lib/python2.7/dist-packages/web/application.py", line 396, in handle_class
    return tocall(*args)
  File "/home/ubuntu/mdm-server/server/API/api.py", line 189, in GET
    COMMAND_QUEUE.get_queue(sql)
  File "/home/ubuntu/mdm-server/server/queue.py", line 165, in get_queue
    self.send_apns(row['udid'], sql)
  File "/home/ubuntu/mdm-server/server/queue.py", line 216, in send_apns
    wrapper.notify()
  File "/usr/local/lib/python2.7/dist-packages/APNSWrapper-0.6.1-py2.7.egg/APNSWrapper/notifications.py", line 194, in notify
    apnsConnection.connect(apnsHost, self.apnsPort)
  File "/usr/local/lib/python2.7/dist-packages/APNSWrapper-0.6.1-py2.7.egg/APNSWrapper/connection.py", line 215, in connect
    self.context().connect(host, port)
  File "/usr/local/lib/python2.7/dist-packages/APNSWrapper-0.6.1-py2.7.egg/APNSWrapper/connection.py", line 161, in connect
    self.connectionContext.connect((host, port))
  File "/usr/lib/python2.7/ssl.py", line 433, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python2.7/ssl.py", line 423, in _real_connect
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 405, in do_handshake
    self._sslobj.do_handshake()
SSLError: [Errno 8] _ssl.c:510: EOF occurred in violation of protocol  

Edit2:ssl.SSLError 处理错误。

Edit3:我确实必须编辑 APNSWrapper 以使用 TLSv1,详见 GitHub 存储库,在服务器设置部分。 Example iOS MDM Server

好的,明白了。当 APNs 服务器无法与预期 phone 通信时,APNSWrapper 会抛出此错误。 (即 phone 关闭或没有接收。)如果其他人遇到此问题,try/except 块捕获 ssl.SSLError 将处理此异常。如果是这种情况,最好推迟对 APNs 的另一次调用。