#Daphne Error

5 messages · Page 1 of 1 (latest)

wraith citrus
#

Django Channels WebSocket 403 & AppRegistryNotReady Issue
Context:
I'm building a chat application using Django REST Framework, Django Channels, Daphne, JWT Authentication, and Zustand for state management. I want to implement direct messaging (not chat rooms) and WebSockets for real-time communication.

Problem:
I've been stuck for 3 days with the following issues:

WebSocket 403 Forbidden when connecting via wscat:

bash
Copy code
❯ wscat -c ws://127.0.0.1:8000/ws/chat/
error: Unexpected server response: 403
Connection refused on port 8001:

bash
Copy code
❯ wscat -c ws://127.0.0.1:8001/ws/chat/
error: connect ECONNREFUSED 127.0.0.1:8001
AppRegistryNotReady: Apps aren't loaded yet when trying to get get_user_model() in consumers.py.
However, after debugging, INSTALLED_APPS is loading correctly.

What I’ve Tried:
✅ Verified that DJANGO_SETTINGS_MODULE=chatroom.settings is correctly set.

✅ Checked INSTALLED_APPS, and all required apps are loaded (daphne, channels, auth, etc.).

✅ Ran print(apps.get_app_configs()) and confirmed apps are loaded.

✅ Tried running daphne -b 127.0.0.1 -p 8001 chatroom.asgi:application.

✅ Used wscat to debug WebSocket connections.

Possible Issues:
🔹 Daphne not running correctly or incorrect ASGI setup.
🔹 WebSocket authentication issue (I'm using JWT authentication).
🔹 Middleware issue blocking WebSocket connections.
🔹 ASGI routing issue (maybe WebSocket URL isn't mapped properly).

Seeking Help:
How can I debug the 403 Forbidden WebSocket issue?
Could authentication be blocking the WebSocket connection?

safe crescent
fallow oyster
#

Or is you code on GitHub so we can test it ourselves?

wraith citrus