python Tornado SSLEOFError : EOF occurred in violation of protocol (_ssl. c:581)

标签 python ios ssl websocket tornado

我正在尝试使用 https 和安全网络套接字 (wss://) 运行聊天应用程序,但出现以下错误。我正在使用我创建的自签名证书。如果我访问我的 site从 chrome 桌面它工作。如果我从 chrome ios 访问同一站点,我会收到以下错误消息。此外,从 chrome ios 中,我收到了不可信证书的警告并接受了它。所以我想让它适用于 chrome ios。

[E 150516 14:01:56 http1connection:700] Uncaught exception
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/http1connection.py", line 691, in _server_request_loop
    ret = yield conn.read_response(request_delegate)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 807, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 209, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 810, in run
    yielded = self.gen.throw(*sys.exc_info())
  File "/usr/local/lib/python2.7/dist-packages/tornado/http1connection.py", line 166, in _read_message
    quiet_exceptions=iostream.StreamClosedError)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 807, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 209, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)

这是我的代码

import tornado.ioloop
import tornado.web
import tornado.options
import tornado.httpserver
import os
import tornado.websocket

import ssl
ssl.PROTOCOL_SSLv23 = ssl.PROTOCOL_TLSv1

clients = []

class IndexHandler(tornado.web.RequestHandler):
  @tornado.web.asynchronous
  def get(request):
    request.render("index.html")

class WebSocketChatHandler(tornado.websocket.WebSocketHandler):
  def open(self, *args):
    print("open", "WebSocketChatHandler")
    clients.append(self)

  def on_message(self, message):        
    print message
    for client in clients:
        client.write_message(message)

  def on_close(self):
    clients.remove(self)

application = tornado.web.Application([(r'/wschat', WebSocketChatHandler), (r'/', IndexHandler)])

data_dir = '/home/bob'

#http_server = tornado.httpserver.HTTPServer(application)
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
    "certfile": os.path.join(data_dir, "myselfsigned.cer"),
    "keyfile": os.path.join(data_dir, "myselfsigned.key"),
})

if __name__ == "__main__":
    tornado.options.parse_command_line()
    http_server.listen(443)
    tornado.ioloop.IOLoop.instance().start()

我正在运行 python 2.7.9 和 tornado 4.1。我怀疑我必须用猴子补丁 Tornado ,但我已经尝试了各种猴子补丁但没有成功。有人可以帮我猴子补丁 Tornado ,或提供有关如何解决此问题的详细步骤。另外,我是 SSL 的新手,所以像我 5 岁一样向我解释 :)

非常感谢您的时间和耐心等待!

最佳答案

根据 https://blog.httpwatch.com/2013/12/12/five-tips-for-using-self-signed-ssl-certificates-with-ios/ ,为了在 iOS 上的 Safari(包括 Chrome)以外的应用程序中使用自签名证书,您必须将该证书安装为“配置文件”。

在服务器端记录的错误是无害的,不会在 Tornado 4.2 中记录得那么详细。

关于 python Tornado SSLEOFError : EOF occurred in violation of protocol (_ssl. c:581),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279152/

相关文章:

python - 在 Bokeh 0.12 中为 Span 添加标签

Python 多处理似乎几乎不可能在类内完成/使用任何类实例。它的预期用途是什么?

ios - ViewWillAppear中的UITableViewScroll

python - Pickle 拒绝使用 celery 报告 ContentDisallowed : Refusing to deserialize untrusted content of type pickle 来序列化内容

ssl - Nginx certbot SSL 不适用于 Cloudflare

python - numpy中的随机单热矩阵

python - 如何使输出图像的大小与原始图像的大小相同以计算CNN中的损失?

ios - 如何更改 AVPlayer 的视频方向?

ios - 使用函数方法查找最小值和最大值时出现性能问题

ssl - 没有 ssl 证书的域重定向到不同的 ssl 域