Skip to content
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 with django 3 #292

Closed
dimkoug opened this issue Dec 15, 2019 · 16 comments
Closed

daphne with django 3 #292

dimkoug opened this issue Dec 15, 2019 · 16 comments

Comments

@dimkoug
Copy link

dimkoug commented Dec 15, 2019

When i ran daphne with unix socket and django version 3 i get this error Django can only handle ASGI/HTTP connections, not websocket.

I try to run the django channels tutorial with nginx gunicorn supervisor and daphne

@dimkoug
Copy link
Author

dimkoug commented Dec 15, 2019

ok i fixed it , i run the server via manage.py to ensure that works and then fix the supervisor about daphne

@dimkoug dimkoug closed this as completed Dec 15, 2019
@Sahil624
Copy link

Hi, I am facing this issue. It works fine on django built-in development server but it throws above error on daphne. I want to run my server on daphne instead of built-in dev server for production.
Any help would be appreciated.

@dimkoug
Copy link
Author

dimkoug commented Dec 29, 2019

Hi, I am facing this issue. It works fine on django built-in development server but it throws above error on daphne. I want to run my server on daphne instead of built-in dev server for production.
Any help would be appreciated.

i will create a a basic project with celery and django channels

https://github.com/dimkoug/celeryproject

@louisliv
Copy link

louisliv commented Jan 4, 2020

I am also experiencing this error

Daphne is spitting out the same error:
Django can only handle ASGI/HTTP connections, not websocket.

@dwjorgeb
Copy link

dwjorgeb commented Jan 5, 2020

I am also experiencing this error

Daphne is spitting out the same error:
Django can only handle ASGI/HTTP connections, not websocket.

@louisliv getting the same issue. Did you manage to fix it?

@louisliv
Copy link

louisliv commented Jan 5, 2020

@dwjorgeb I did not. I can confirm it works using Django's runserver command instead of daphne, but I would prefer not to use Django's built in server for production.

@dwjorgeb
Copy link

dwjorgeb commented Jan 5, 2020

@louisliv same, I can't use Django's built-in server for production. It's weird that I can't find any documentation, either on Channels or on Django about this apparent incompability

@Sahil624
Copy link

Sahil624 commented Jan 5, 2020

I managed to fix by using "get_default_application()" instead of "get_asgi_application()" in asgi.py . I don't have access to my system at this point so can't share exact code. Let me know if issue still persists.

@dwjorgeb
Copy link

dwjorgeb commented Jan 5, 2020

@Sahil624 Where do you imported it? I don't have a get_default_application, only get_asgi_application and get_wsgi_application, neither of them work, as if I use wsgi one the server can't interact with it.

@Sahil624
Copy link

Sahil624 commented Jan 5, 2020

My asgi.py file looks like this.

"""
ASGI config for server project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os
import django

# from django.core.asgi import get_asgi_application
from channels.routing import get_default_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
django.setup()
# application = get_asgi_application()
application = get_default_application()

@louisliv
Copy link

louisliv commented Jan 5, 2020

@Sahil624 that worked for me.

@dwjorgeb
Copy link

dwjorgeb commented Jan 5, 2020

@Sahil624 thanks, that actually worked for me. We can't use Django 3's ASGI file, we need to overwrite the ASGI file with the Channels' code (the one you put above, from here: https://channels.readthedocs.io/en/latest/deploying.html#run-protocol-servers )

thanks for pointing me in the right direction!

@carltongibson
Copy link
Member

Django 3.0 does not support websockets. Continue to use Channels for this.

@Sahil624
Copy link

Sahil624 commented Jan 7, 2020

Glad it worked for all.

@KartheekL
Copy link

@Sahil624 can you help me with running a default method as soon as the server is run?

@debasisnath
Copy link

Sahil624 you save me. I am so thankful for what you did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants