-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Daphne 3.0.1 Apps aren't loaded yet. #347
Comments
Hi @Altroo. See the updated deployment docs here: https://channels.readthedocs.io/en/stable/deploying.html#configuring-the-asgi-application I think the issue will be the JWT auth middleware. Looks like it's accessing the user model before this line:
I'd say that if you move that import below there it should work. |
You're a wizard harry ! thank's alot it really worked, many daphne users really have this same issue on stackoverflow, your answer will save them. |
Worked for me too. |
Man, you don't know how much I apreciatte this answer. Thanks! |
Can't thank you enough man. I read through this document but somehow missed that! Thanks for pointing it out. Spent all day on this problem. Problem solved. Though seems like my media files aren't loading anymore. i will find out why. Meanwhile I am just happy the server is back up! |
Very thanks man!!! I missed completely that documentation part |
I was stuck on this for 2 days until I found this post. In my case, Visual Studio Code auto-formatter did the bulk of the work for me and re-arranged my imports, making the get_asgi_application() be down the line. |
Another tip: you can add "# isort: skip_file" to the beginning of your asgi.py to prevent isort from reordering automatically. |
This just saved me. Thank you so much. |
Hello I'm facing this issue on daphne 3.0.1 :
` ● daphne.service - daphne daemon
Loaded: loaded (/etc/systemd/system/daphne.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-11-24 15:13:06 UTC; 5s ago
Process: 3125951 ExecStart=/usr/local/bin/daphne -u /home/git/demo_API/www/demo_ws.sock demo_API.asgi:application -v 1 --access-log /home/git/demo_API/www/logs/debug.log (code=exited, status=1/FAILURE)
Main PID: 3125951 (code=exited, status=1/FAILURE)
Nov 24 15:13:06 ubuntu daphne[3125951]: class AbstractBaseUser(models.Model):
Nov 24 15:13:06 ubuntu daphne[3125951]: File "/home/git/.local/lib/python3.8/site-packages/django/db/models/base.py", line 108, in __ new __
Nov 24 15:13:06 ubuntu daphne[3125951]: app_config = apps.get_containing_app_config(module)
Nov 24 15:13:06 ubuntu daphne[3125951]: File "/home/git/.local/lib/python3.8/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
Nov 24 15:13:06 ubuntu daphne[3125951]: self.check_apps_ready()
Nov 24 15:13:06 ubuntu daphne[3125951]: File "/home/git/.local/lib/python3.8/site-packages/django/apps/registry.py", line 136, in check_apps_ready
Nov 24 15:13:06 ubuntu daphne[3125951]: raise AppRegistryNotReady("Apps aren't loaded yet.")
Nov 24 15:13:06 ubuntu daphne[3125951]: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. `
I'm running :
python 3.8.5
daphne v3.0.1
gunicorn v20.0.4
nginx v1.18.0
redis v3.5.3
channels v3.0.2
channels-redis v3.2.0
django v3.1.3
asgi.py :
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from chat.auth.jwt_auth_middleware import SimpleJwtTokenAuthMiddleware
from chat import routing as core_routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_API.settings')
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter({
"http": django_asgi_app,
"websocket": SimpleJwtTokenAuthMiddleware(
URLRouter(
core_routing.websocket_urlpatterns
)
),
})
routing.py (in chat app) :
from . import consumers
from django.urls import re_path
websocket_urlpatterns = [
re_path(r'^chatws$', consumers.ChatConsumer.as_asgi()),
]
settings.py :
INSTALLED_APPS = [
'channels',
'chat',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_simplejwt',
]
ASGI_APPLICATION = 'demo_API.asgi.application'`CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": ['127.0.0.1', 6379)],
},
},
}
`
wsgi.py :
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_API.settings')
application = get_wsgi_application()
/etc/systemd/system/daphne.service :
[Unit]
Description=daphne daemon
After=network.target
[Service]
PIDFile=/run/daphne/pid
User=git
Group=www-data
WorkingDirectory=/home/git/demo_API/www/
Environment="DJANGO_SETTINGS_MODULE=demo_API.settings"
ExecStart=/home/git/demo_API/www/venv/bin/daphne -u /home/git/demo_API/www/demo_chat.sock
demo_API.asgi:application -v 1 --access-log /home/git/demo_API/www/logs/debug.log
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
Restart=on-abort
PrivateTmp=true
[Install]
WantedBy=multi-user.target
If i get everything back to old version it works again using old channels code & files.
channels==2.4.0
daphne==2.5.0
channels-redis==2.4.1
Things i tried so far :
Removing all old daphne versions.
Installing daphne using a superuser session.
Changing the order of installed apps on settings.py.
Running daphne without -u .sock.
Tested AuthMiddleware instead of my custom SimpleJwtTokenAuthMiddleware in asgi.py + testing without Auths.
Running daphne command line directly on django folder.
And nothing seems to work so far.
Also same error on local running just : daphne demo_API.asgi:application
Details :
(venv) altroo@Altroo demo_API % daphne demo_API.asgi:application
Traceback (most recent call last):
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/bin/daphne", line 8, in
sys.exit(CommandLineInterface.entrypoint())
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/daphne/cli.py", line 170, in entrypoint
cls().run(sys.argv[1:])
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/daphne/cli.py", line 232, in run
application = import_by_path(args.application)
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/daphne/utils.py", line 12, in import_by_path
target = importlib.import_module(module_path)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "./demo_API/asgi.py", line 15, in
from chat.auth.jwt_auth_middleware import SimpleJwtTokenAuthMiddleware
File "./chat/auth/jwt_auth_middleware.py", line 1, in
from channels.auth import AuthMiddlewareStack
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/channels/auth.py", line 12, in
from django.contrib.auth.models import AnonymousUser
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/contrib/auth/models.py", line 2, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 48, in
class AbstractBaseUser(models.Model):
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/db/models/base.py", line 108, in __ new __
app_config = apps.get_containing_app_config(module)
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
self.check_apps_ready()
File "/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/apps/registry.py", line 136, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Any help or suggestions will be apreciated.
The text was updated successfully, but these errors were encountered: