Python 3.x 未捕获类型错误:无法读取属性';sid';未定义的
我正在python react应用程序中使用Python 3.x 未捕获类型错误:无法读取属性';sid';未定义的,python-3.x,reactjs,socket.io,python-socketio,Python 3.x,Reactjs,Socket.io,Python Socketio,我正在python react应用程序中使用socket.io,使用python socketio和socket.io客户端。客户端在连接到服务器时以及触发connect事件之前显示错误 服务器: import asyncio from aiohttp import web import socketio from aiohttp_middlewares import cors_middleware from aiohttp_middlewares.cors import DEFAULT_ALL
socket.io
,使用python socketio
和socket.io客户端
。客户端在连接到服务器时以及触发connect
事件之前显示错误
服务器:
import asyncio
from aiohttp import web
import socketio
from aiohttp_middlewares import cors_middleware
from aiohttp_middlewares.cors import DEFAULT_ALLOW_HEADERS
sio = socketio.AsyncServer(async_mode='aiohttp',cors_allowed_origins='*')
app=web.Application()
sio.attach(app)
async def index(request):
return web.Response(text="hello", content_type='text/html')
@sio.event
async def connect(sid, environ):
print('Client connected',sid)
await sio.emit('message', "good")
@sio.event
def disconnect(sid):
print('Client disconnected',sid)
@sio.on('message')
async def print_message(sid, message):
print("Socket ID: " , sid)
print(message)
app.router.add_get('/', index)
if __name__ == '__main__':
web.run_app(app)
客户(反应):
控制台中打印的错误:
这些文件与socket.io客户端相关
Uncaught TypeError: Cannot read property 'sid' of undefined
at Socket.onpacket (socket.js:189)
at Manager.<anonymous> (index.js:21)
at Manager.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at Manager.ondecoded (manager.js:209)
at Decoder.<anonymous> (index.js:21)
at Decoder.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at Decoder.add (index.js:117)
at Manager.ondata (manager.js:201)
at Socket.<anonymous> (index.js:21)
at Socket.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at Socket.onPacket (socket.js:387)
at WS.<anonymous> (socket.js:196)
at WS.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at WS.onPacket (transport.js:103)
at WS.onData (transport.js:96)
at WebSocket.ws.onmessage (websocket.js:115)
Uncaught TypeError:无法读取未定义的属性“sid”
位于Socket.onpacket(Socket.js:189)
在经理那儿。(索引:21)
在Manager.push../node_modules/component emitter/index.js.emitter.emit(index.js:145)
在Manager.com上(Manager.js:209)
在解码器。(索引:21)
在Decoder.push../node_modules/component emitter/index.js.emitter.emit(index.js:145)
在Decoder.add(index.js:117)
在Manager.ondata(Manager.js:201)
在插座上。(索引:21)
在Socket.push../node_modules/component emitter/index.js.emitter.emit(index.js:145)处
位于Socket.onPacket(Socket.js:387)
在WS。(socket.js:196)
在WS.push../node_modules/component emitter/index.js.emitter.emit(index.js:145)
在WS.onPacket(transport.js:103)
在WS.onData(transport.js:96)
在WebSocket.ws.onmessage(WebSocket.js:115)
在Node.js上使用最新版本的socket.io-client时,我遇到了相同的错误。如果我使用像v2.3.0这样的旧版本,我不会得到任何错误
我知道这次降级解决了一些人的问题,但如果你想使用最新版本(我不是socket.io方面的专家),请查看这篇文章,他们讨论了API中的一些更改,并解决了一些不一致的问题:
您能否添加有关错误的更多详细信息,以便无需猜测?例如,包含堆栈跟踪。我现在添加了它。谢谢。当我把这个版本降级的时候,它并没有引起任何的错误。
Uncaught TypeError: Cannot read property 'sid' of undefined
at Socket.onpacket (socket.js:189)
at Manager.<anonymous> (index.js:21)
at Manager.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at Manager.ondecoded (manager.js:209)
at Decoder.<anonymous> (index.js:21)
at Decoder.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at Decoder.add (index.js:117)
at Manager.ondata (manager.js:201)
at Socket.<anonymous> (index.js:21)
at Socket.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at Socket.onPacket (socket.js:387)
at WS.<anonymous> (socket.js:196)
at WS.push../node_modules/component-emitter/index.js.Emitter.emit (index.js:145)
at WS.onPacket (transport.js:103)
at WS.onData (transport.js:96)
at WebSocket.ws.onmessage (websocket.js:115)