2016-10-11 30 views
1

這是一個簡單的代碼片斷,不斷重複我遇到的問題。我使用Python 2.7.12,Flask 0.11,Flask-SocketIO 2.7.1和gevent 1.1.2。我知道這可能是一個更好的問題,可以提交給負責包裹的郵件列表,但我無法弄清楚哪一個負責。但是,我很確定這是gevent的問題,因爲這引發了異常。爲什麼Flask + SocketIO + Gevent會給我SSL EOF錯誤?

from flask import Flask 
from flask_socketio import SocketIO 

from gevent import monkey 
monkey.patch_all() 

import ssl 

app = Flask(__name__) 
app.config['SECRET_KEY'] = 'secret' 

socketio = SocketIO(app, async_mode='gevent') 

@app.route('/') 
def index(): 
    return "Hello World!" 

@socketio.on('connect') 
def handle_connect_event(): 
    print('Client connected') 

if __name__ == '__main__': 
    socketio.run(app, host='127.0.0.1', port=8443, 
       certfile='ssl/server/server.cer', keyfile='ssl/server/server.key', 
       ca_certs='ssl/server/ca.cer', cert_reqs=ssl.CERT_REQUIRED, 
       ssl_version=ssl.PROTOCOL_TLSv1_2) 

這裏是我得到當客戶端連接錯誤:

Traceback (most recent call last): 
    File "/usr/lib/python2.7/site-packages/gevent/greenlet.py", line 534, in 
    result = self._run(*self.args, **self.kwargs) 
    File "/usr/lib/python2.7/site-packages/gevent/baseserver.py", line 25, in 
    return handle(*args_tuple) 
    File "/usr/lib/python2.7/site-packages/gevent/server.py", line 126, in wr 
    ssl_socket = self.wrap_socket(client_socket, **self.ssl_args) 
    File "/usr/lib/python2.7/site-packages/gevent/_sslgte279.py", line 691, i 
    ciphers=ciphers) 
    File "/usr/lib/python2.7/site-packages/gevent/_sslgte279.py", line 271, i 
    raise x 

    SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590) 
    <Greenlet at 0x7fdd593c94b0: _handle_and_close_when_done(<bound method WSGInd method WSGIServer.do_close of <WSGIServer a, (<socket at 0x7fdd590f4410 SSLEOFError 

我的系統也有OpenSSL的版本1.0.2.j是否有幫助。任何想法,將不勝感激!

+0

這是之前向我報告的(請參閱https://github.com/miguelgrinberg/Flask-SocketIO/issues/88),但從未發現問題所在。這很可能是一個與gevent相關的bug。如果您有可以配置爲終止SSL的代理服務器,您可能可以繞過此問題,因爲我所鏈接的錯誤報告中的人員確實如此。 – Miguel

回答

0

在代碼的頂部使用patch_all。甚至在燒瓶和燒杯進口之前。

from gevent import monkey 
monkey.patch_all() 

from flask import Flask 
from flask_socketio import SocketIO 

import ssl 
+0

這似乎沒有幫助。 – smbullet

相關問題