Django Websocket receive and send arguments missing
TypeError at /ws/status/ app() missing 2 required positional arguments: 'receive' and 'send'
I got only receive and send 2 positional argument error for websocket in django rest framework. How can i fix it ? Maybe version error but i tried to change django channels versions but dont works
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(
core.routing.websocket_urlpatterns
)
)
),
})
websocket_urlpatterns = [
re_path(r'ws/status/$', StatusConsumer.as_asgi()),
]
Traceback (most recent call last):
File "/usr/local/bin/daphne", line 8, in <module>
sys.exit(CommandLineInterface.entrypoint())
File "/usr/local/lib/python3.8/dist-packages/daphne/cli.py", line 170, in entrypoint
cls().run(sys.argv[1:])
File "/usr/local/lib/python3.8/dist-packages/daphne/cli.py", line 232, in run
application = import_by_path(args.application)
File "/usr/local/lib/python3.8/dist-packages/daphne/utils.py", line 12, in import_by_path
target = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Application/./core/asgi.py", line 5, in <module>
import core.routing
File "/Application/./core/routing.py", line 2, in <module>
from .consumers import StatusConsumer
File "/Application/./core/consumers.py", line 7, in <module>
User = get_user_model()
File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/__init__.py", line 170, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 102, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 82, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
root@ubuntu-4gb-hel1-4://Application# export DJANGO_SETTINGS_MODULE=mysite.settings
root@ubuntu-4gb-hel1-4://Application# export DJANGO_SETTINGS_MODULE=core.settings
root@ubuntu-4gb-hel1-4://Application# /usr/local/bin/daphne -v 2 -p 9001 core.asgi:application
2024-07-09 18:36:33,449 INFO Starting server at tcp:port=9001:interface=127.0.0.1
2024-07-09 18:36:33,450 INFO HTTP/2 support enabled
2024-07-09 18:36:33,451 INFO Configuring endpoint tcp:port=9001:interface=127.0.0.1
2024-07-09 18:36:33,451 INFO HTTPFactory starting on 9001
2024-07-09 18:36:33,452 INFO Starting factory <daphne.http_protocol.HTTPFactory object at 0x7fcd025fc5b0>
2024-07-09 18:36:33,452 INFO Listening on TCP address 127.0.0.1:9001
2024-07-09 18:36:37,435 DEBUG HTTP b'GET' request for ['127.0.0.1', 47020]
Internal Server Error: /ws/status/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/asgiref/sync.py", line 518, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
TypeError: app() missing 2 required positional arguments: 'receive' and 'send'
2024-07-09 18:36:37,535 ERROR Internal Server Error: /ws/status/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/asgiref/sync.py", line 518, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
TypeError: app() missing 2 required positional arguments: 'receive' and 'send'
2024-07-09 18:36:37,539 DEBUG HTTP 500 response started for ['127.0.0.1', 47020]
2024-07-09 18:36:37,540 DEBUG HTTP close for ['127.0.0.1', 47020]
2024-07-09 18:36:37,540 INFO "127.0.0.1" - - [09/Jul/2024:14:36:37 +0000] "GET /ws/status/ HTTP/1.1" 500 51608 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
2024-07-09 18:36:37,541 DEBUG HTTP response complete for ['127.0.0.1', 47020]
127.0.0.1:47020 - - [09/Jul/2024:18:36:37] "GET /ws/status/" 500 51608
2024-07-09 18:36:38,535 DEBUG HTTP b'GET' request for ['127.0.0.1', 47030]
Internal Server Error: /ws/status/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/asgiref/sync.py", line 518, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
TypeError: app() missing 2 required positional arguments: 'receive' and 'send'
2024-07-09 18:36:38,565 ERROR Internal Server Error: /ws/status/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/asgiref/sync.py", line 518, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
TypeError: app() missing 2 required positional arguments: 'receive' and 'send'
2024-07-09 18:36:38,569 DEBUG HTTP 500 response started for ['127.0.0.1', 47030]
2024-07-09 18:36:38,570 DEBUG HTTP close for ['127.0.0.1', 47030]
2024-07-09 18:36:38,570 INFO "127.0.0.1" - - [09/Jul/2024:14:36:38 +0000] "GET /ws/status/ HTTP/1.1" 500 51608 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
2024-07-09 18:36:38,570 DEBUG HTTP response complete for ['127.0.0.1', 47030]
127.0.0.1:47030 - - [09/Jul/2024:18:36:38] "GET /ws/status/" 500 51608
I tried for websocket with daphne, in nginx. but only i got it.