question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Django can only handle ASGI/HTTP connections, not websocket.

See original GitHub issue

my setup:

Django==3.0.3
channels==2.4.0
channels-redis==2.4.2
daphne==2.4.1

run command:

daphne myproduct.asgi:application

I got 500 server error when I connenct websocket .

log:

127.0.0.1:54023 - - [12/Mar/2020:16:51:21] "WSCONNECTING /ws/robot" - -
2020-03-12 16:51:22,104 ERROR    Exception inside application: Django can only handle ASGI/HTTP connections, not websocket.
  File "/Users/xx/project/xx/venv/lib/python3.7/site-packages/daphne/cli.py", line 30, in asgi
    await self.app(scope, receive, send)
  File "/Users/xx/project/xx/venv/lib/python3.7/site-packages/django/core/handlers/asgi.py", line 146, in __call__
    % scope['type']
  Django can only handle ASGI/HTTP connections, not websocket.
127.0.0.1:54023 - - [12/Mar/2020:16:51:22] "WSDISCONNECT /ws/robot" - -

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
carltongibsoncommented, Apr 7, 2020

Hi @jack-michaud. Yes. Currently this is the case. It’s a difference between ASGI v2 and v3.

Progress for this should be made in #1421 by @jaydenwindle. At that point we should be able to accept a single callable (the ASGI v3 version that Django’s new code implements) and the idea above should hold. 🤞

Goal now is a channels update to use ASGI 3 (allowing fallback for existing apps) throughout. I have stuff for the next version of DRF top of my list, and then it’s Channels after that. If you fancy lending a hand, that would be super.

0reactions
ribenzcommented, Nov 4, 2021

Hey everyone, when I change django.core.asgi.get_asgi_application to from channels.routing import get_default_application, it gives me this error: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. This is the full traceback:

Traceback (most recent call last):
  File "/home/admin/code/outpost/env/bin/daphne", line 8, in <module>
    sys.exit(CommandLineInterface.entrypoint())
  File "/home/admin/code/outpost/env/lib/python3.10/site-packages/daphne/cli.py", line 170, in entrypoint
    cls().run(sys.argv[1:])
  File "/home/admin/code/outpost/env/lib/python3.10/site-packages/daphne/cli.py", line 232, in run
    application = import_by_path(args.application)
  File "/home/admin/code/outpost/env/lib/python3.10/site-packages/daphne/utils.py", line 12, in import_by_path
    target = importlib.import_module(module_path)
  File "/home/admin/.python/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/admin/code/outpost/outpostsite/./outpostsite/asgi.py", line 22, in <module>
    application = get_default_application()
  File "/home/admin/code/outpost/env/lib/python3.10/site-packages/channels/routing.py", line 28, in get_default_application
    module = importlib.import_module(path)
  File "/home/admin/.python/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/admin/code/outpost/outpostsite/./outpostsite/routing.py", line 3, in <module>
    import backend.routing
  File "/home/admin/code/outpost/outpostsite/./outpostsite/apps/backend/routing.py", line 2, in <module>
    from backend.consumers import *
  File "/home/admin/code/outpost/outpostsite/./outpostsite/apps/backend/consumers.py", line 3, in <module>
    from backend.models import *
  File "/home/admin/code/outpost/outpostsite/./outpostsite/apps/backend/models.py", line 9, in <module>
    class modelname(Model):
  File "/home/admin/code/outpost/env/lib/python3.10/site-packages/django/db/models/base.py", line 108, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/admin/code/outpost/env/lib/python3.10/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
    self.check_apps_ready()
  File "/home/admin/code/outpost/env/lib/python3.10/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.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Django can only handle ASGI/HTTP connections, not websocket
I initially thought it didn't, because I didn't see that it also changed from django.core.asgi import get_asgi_application to from channels.
Read more >
Django can only handle ASGI/HTTP connections, not ...
Coding example for the question Django daphne asgi: Django can only handle ASGI/HTTP connections, not websocket-django.
Read more >
Django can only handle ASGI/HTTP connections, not websocket
Answer a question Hello I am getting a error. Before coming here, I tried many different ways and looked at the topics that...
Read more >
How to Add Websockets to a Django App without Extra ...
In this post, you'll learn how to handle Websockets with Django by ... Django 3.0 is only compatible with Python 3.6 and up...
Read more >
daphne - PyPI
Django ASGI (HTTP /WebSocket) server. ... Daphne only supports “normal” requests over HTTP/2 at this time; there is not yet support for extended...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found