TypeError: object NoneType can't be used in 'await' expression when testing to group.send. Errror only occurs on when deployed to Kuberentes.
GabrielDealca opened this issue · comments
This line causes the error
async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
I checked channel_layer, it is not empty or not None, so I don't understand what is the NoneType pertaining to. I am using Django channels Daphne connected to Redis Memorystore. I tested connection to redis memorystore using the redis library, and it is accessible, so I don't think communication with the backend is the problem(?).
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/asgiref/sync.py", line 486, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
File "/usr/local/lib/python3.9/site-packages/asgiref/sync.py", line 448, in __call__
ret = await asyncio.wait_for(future, timeout=None)
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
return await fut
File "/usr/local/lib/python3.9/site-packages/asgiref/current_thread_executor.py", line 22, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.9/site-packages/asgiref/sync.py", line 490, in thread_handler
return func(*args, **kwargs)
File "/lifgame-django/./base/views.py", line 320, in index
async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
File "/usr/local/lib/python3.9/site-packages/asgiref/sync.py", line 240, in __call__
return call_result.result()
File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
raise self._exception
File "/usr/local/lib/python3.9/site-packages/asgiref/sync.py", line 306, in main_wrap
result = await self.awaitable(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/channels_redis/core.py", line 198, in send
await connection.zremrangebyscore(
File "/usr/local/lib/python3.9/site-packages/redis/asyncio/client.py", line 513, in execute_command
conn = self.connection or await pool.get_connection(command_name, **options)
File "/usr/local/lib/python3.9/site-packages/redis/asyncio/connection.py", line 1375, in get_connection
await connection.connect()
TypeError: object NoneType can't be used in 'await' expression
Have been stuck with this issue for almost a week now. Any help would be very much appreciated.
Your connection object is None. So I'd guess the way you're passing config to k8s isn't working. (Did your environment variables not load?)
This isn't a channels issue really sorry.
Your connection object is None. So I'd guess the way you're passing config to k8s isn't working. (Did your environment variables not load?)
This isn't a channels issue really sorry.
Thank you for replying, my env variables are purely hard coded and not passed to env variables for the sake of testing this, so you think there is a problem with my CHANNEL_LAYERS config? though I use channels_redis there for the backend, so this might be an issue on the wrong repo?
if you don't mind, could you provide the code for your consumer?
if you don't mind, could you provide the code for your consumer?
The errors already occur with the 1 line of code I provided, but similar error to this consumer class as well
class ThisConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.user = self.scope['user']
self.group_name = f'user_{self.user.id}'
await self.channel_layer.group_add(self.group_name, self.channel_name) # error occurs here
await self.accept()
if you don't mind, could you provide the code for your consumer?
The errors already occur with the 1 line of code I provided, but similar error to this consumer class as well
class ThisConsumer(AsyncWebsocketConsumer): async def connect(self): self.user = self.scope['user'] self.group_name = f'user_{self.user.id}' await self.channel_layer.group_add(self.group_name, self.channel_name) # error occurs here await self.accept()
Everything here seems to be fine...
Errror only occurs on when deployed to Kuberentes.
The error will be with the deployment, not with the Channels code.
Errror only occurs on when deployed to Kuberentes.
The error will be with the deployment, not with the Channels code.
Can you please expound on this? What's the difference in terms of setup locally versus deployment to make this work?