gpt4 book ai didi

javascript - 设置 SocketIO 和 Flask 我收到此错误 : "UnboundLocalError: local variable ' ssl_socket' referenced before assignment"

转载 作者:太空宇宙 更新时间:2023-11-03 20:34:19 25 4
gpt4 key购买 nike

我正在使用 Flask 设置 socketio,但遇到一些错误,导致其无法运行。

File "src/gevent/greenlet.py", line 705, in gevent._greenlet.Greenlet.run     
File "/Users/hairy/anaconda2/lib/python2.7/site-packages/gevent/baseserver.py", line 26, in _handle_and_close_when_done
return handle(*args_tuple)
File "/Users/hairy/anaconda2/lib/python2.7/site-packages/gevent/server.py", line 193, in wrap_socket_and_handle
ssl_socket.close()
UnboundLocalError: local variable 'ssl_socket' referenced before assignment
2019-07-30T15:07:15Z <Greenlet "Greenlet-0" at 0x102908500: _handle_and_close_when_done(<bound method WSGIServer.wrap_socket_and_handle of, <bound method WSGIServer.do_close of <WSGIServer a, (<socket at 0x1067882d0 fileno=[Errno 9] Bad file )> failed with UnboundLocalError

这是我的 flask 代码:

from flask import Flask, render_template, Markup
from util import getHtml, duplicate, displayArray
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

@app.route('/')
def home():
return displayArray()
@socketio.on('connect')
def test_connect():
emit('after connect', {'data':'Lets dance'})
@socketio.on('plz reload', namespace='/test')
def test_message(message):
emit('reload', {'data': message['data']})

if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', Debug=True)

这是我的js代码:

$(document).ready(function(){
var socket = io.connect('http://localhost:5000');
// var socket = io.connect('http://' + document.domain + ':' + location.port + '/test');
// var socket = io.connect('http://localhost:5000');
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
socket.on('reload', function(msg) {
$('#log').append('<p>Received: ' + msg.data + '</p>');
location.reload();
});
});

当我访问 localhost:5000 时,应用程序无法加载

最佳答案

我通过更改修复了它

    var socket = io.connect('http://localhost:5000');

var socket = io.connect();

在js中。我不确定为什么会解决这个问题,但它确实解决了。

关于javascript - 设置 SocketIO 和 Flask 我收到此错误 : "UnboundLocalError: local variable ' ssl_socket' referenced before assignment",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57275180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com