2

I wrote Django Channels for practice.

Use Daphne

daphne project.asgi:application

Everything works well.

Use uvicorn

uvicorn project.asgi:application

Error on the page

(index):16 WebSocket connection to'ws://127.0.0.1:8000/ws/chat/123/' failed: Error during WebSocket handshake: Unexpected response code: 400

I don't know where I went wrong.

I follow the official use

python -m pip install uvicorn gunicorn

gunicorn project.asgi:application -k uvicorn.workers.UvicornWorker

Error on the page

(index):16 WebSocket connection to'ws://127.0.0.1:8000/ws/chat/123/' failed: Error during WebSocket handshake: Unexpected response code: 400

Please help me where I need to improve, thank you.

dudulu
  • 754
  • 6
  • 17
  • 1
    Django Channel is generally works well with Daphne. do you have any requirement to use uvicorn? – omid Aug 03 '21 at 12:25
  • I just want to know if uvicorn can be used with Django Channel, but uvicorn is not necessary. – dudulu Aug 04 '21 at 05:38

1 Answers1

2

If you want to use websockets, you need to install uvicorn[standard]:

pip install uvicorn[standard]

See also https://www.uvicorn.org/#quickstart

cmile
  • 36
  • 2