Reputation: 31
so I've been trying to implement django-private-chat into an existing problem but always encountered an error. So, I tried to run the example project found on under django-private-chat on Github and I received the same error. Thanks for the help!
25.04.20 10:45:49:ERROR:Error in connection handler
Traceback (most recent call last):
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/websockets/server.py", line 191, in handler
await self.ws_handler(self, path)
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django_private_chat/handlers.py", line 259, in main_handler
user_owner = get_user_from_session(session_id)
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django_private_chat/utils.py", line 15, in get_user_from_session
session = Session.objects.get(session_key=session_key)
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/db/models/query.py", line 411, in get
num = len(clone)
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/db/models/query.py", line 258, in __len__
self._fetch_all()
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/db/models/query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/db/models/query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1142, in execute_sql
cursor = self.connection.cursor()
File "/opt/anaconda3/envs/testEnv/lib/python3.7/site-packages/django/utils/asyncio.py", line 24, in inner
raise SynchronousOnlyOperation(message)
django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
25.04.20 10:45:49:DEBUG:server ! failing OPEN WebSocket connection with code 1011
25.04.20 10:45:49:DEBUG:server - state = CLOSING
25.04.20 10:45:49:DEBUG:server > Frame(fin=True, opcode=8, data=b'\x03\xf3', rsv1=False, rsv2=False, rsv3=False)
25.04.20 10:45:49:DEBUG:server x half-closing TCP connection
25.04.20 10:45:49:DEBUG:server - event = connection_lost(None)
25.04.20 10:45:49:DEBUG:server - state = CLOSED
25.04.20 10:45:49:DEBUG:server x code = 1006, reason = [no reason]
Upvotes: 2
Views: 288
Reputation: 11
Django private CHAT isn't supported beyond Django 3.Try entering this in your settings.py file
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
Upvotes: 1