Issue setting up AsyncServer - Multiple errors #1177
-
My server.py import configparser
from dotenv import load_dotenv
from aiohttp import web
import socketio
from SomethingExec import SomethingExecNamespace
load_dotenv()
sio = socketio.AsyncServer(namespaces='*',async_mode='aiohttp')
app = web.Application()
sio.attach(app)
sio.register_namespace(SomethingExecNamespace('/api/killbill'))
if __name__ == '__main__':
web.run_app(app) SomethingExec.py import socketio
import os
class SomethingExecNamespace(socketio.AsyncClientNamespace,socketio.Namespace):
def on_connect(self, sid, environ):
print('Connected')
pass
def on_disconnect(self, sid):
print('Disconnected')
pass
async def on_killbill(self,sid, data):
print('On Kill Bill Invoked {} {}'.format(sid,data))
await self.emit('on_killedbill',data) First without including both raise ValueError('Not a namespace instance')
ValueError: Not a namespace instance After including both (deriving from both), upon invoking the Task exception was never retrieved
future: <Task finished name='Task-18' coro=<AsyncServer._handle_event_internal() done, defined at \venv\lib\site-packages\socketio\asyncio_server.py:522> exception=AttributeError("'NoneType' object has no attribute 'emit'")>
Traceback (most recent call last):
File "\venv\lib\site-packages\socketio\asyncio_server.py", line 524, in _handle_event_internal
r = await server._trigger_event(data[0], namespace, sid, *data[1:])
File "\venv\lib\site-packages\socketio\asyncio_server.py", line 569, in _trigger_event
return await self.namespace_handlers[namespace].trigger_event(
File "\venv\lib\site-packages\socketio\asyncio_namespace.py", line 178, in trigger_event
ret = await handler(*args)
File "\SomethingExec.py", line 21, in on_killbill
await self.emit('on_killedbill',data)
File "\venv\lib\site-packages\socketio\asyncio_namespace.py", line 194, in emit
return await self.client.emit(event, data=data,
AttributeError: 'NoneType' object has no attribute 'emit' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The error that you have is that you are using the |
Beta Was this translation helpful? Give feedback.
-
Thank you @miguelgrinberg, how silly that I didn't catch it. |
Beta Was this translation helpful? Give feedback.
The error that you have is that you are using the
AsyncClientNamespace
, which is used with clients. The correct class to use in a server isAsyncNamespace
.