Djangorestframework не работает, когда применяется канал django

Я разрабатываю приложение для чата, которое позволяет социальный вход. При разработке всех функций restapi, включая функции социального входа, и разработке чат-клиентов с использованием библиотек каналов, возникла проблема с социальным входом. Этот код представляет собой chatcustomer с использованием websocketcunsumer.

import json
from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer
from .models import *
class ChatConsumer(WebsocketConsumer):
    def connect(self):
        self.room_name = self.scope['url_route']['kwargs']['room_name']
        self.room_group_name = 'chat_%s' % self.room_name
        # Join room group
        async_to_sync(self.channel_layer.group_add)(
            self.room_group_name,
            self.channel_name
        )
        self.accept()

    def disconnect(self, close_code):
        # Leave room group
        async_to_sync(self.channel_layer.group_discard)(
            self.room_group_name,
            self.channel_name
    ....

это настройка для канала

INSTALLED_APPS = [
     'channels',
]
ASGI_APPLICATION = 'project.routing.application'

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    }
} 

routing.py в корне проекта

  from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import chat.routing


application = ProtocolTypeRouter({
    'websocket': AuthMiddlewareStack(
        URLRouter(
            chat.routing.websocket_urlpatterns
        )
    ),
})

asgi.py

import os
import django

from channels.routing import get_default_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
django.setup()
application = get_default_application()

routing.py in chatapp

from django.urls import re_path

from . import consumers
websocket_urlpatterns = [
    re_path(r'ws/chat/(?P<room_name>\w+)/$', consumers.ChatConsumer.as_asgi()),
]

это социальный логин views.py


@api_view(['POST'])    
def authenticate_kakao(request):

    access_token = request.data["access_token"]
    code =request.data['code']
    """
    Email Request
    """
    print("process1")
    profile_request = requests.get(
        "https://kapi.kakao.com/v2/user/me", headers={"Authorization": f"Bearer {access_token}"})
    print("process2")
    profile_json = profile_request.json()
    kakao_account = profile_json.get('kakao_account')

    email = kakao_account.get('email')
    profile = kakao_account.get("profile")
    nickname = profile.get("nickname")
    profile_image = profile.get("profile_image_url") 
    print("process3")
    """
    Signup or Signin Request
    """
    try:
        user = User.objects.get(email=email)
        social_user = SocialAccount.objects.get(user=user)
        if social_user is None:
            return Response({'err_msg': 'email exists but not social user'}, status=status.HTTP_400_BAD_REQUEST)
        if social_user.provider != 'kakao':
            return Response({'err_msg': 'no matching social type'}, status=status.HTTP_400_BAD_REQUEST)
        data = {'access_token': access_token, 'code': code}    
        accept = requests.post("http://localhost:8000/accounts/kakao/login/allauth/", data=data)
        print("process5")
        accept_status = accept.status_code
        if accept_status != 200:
            return Response({'err_msg': 'failed to signin'}, status=accept_status)
        accept_json = accept.json()
        #User model update
        print("process6")
        return Response(accept_json)
    except User.DoesNotExist:
        data = {'access_token': access_token, 'code': code}
        accept = requests.post(
            "http://localhost:8000/accounts/kakao/login/allauth/", data=data)
        
        print("process7")
        accept_status = accept.status_code
        if accept_status != 200:
            return Response({'err_msg': 'failed to signup'}, status=accept_status)
        print("process8")
        accept_json = accept.json()
        #User model update
        print("process9")
        return Response(accept_json)

class KakaoLogin(SocialLoginView):
    adapter_class = kakao_view.KakaoOAuth2Adapter
    client_class = OAuth2Client

и urls.py

urlpatterns = [
    path('kakao/authenticate/', login.authenticate_kakao),
    path('kakao/login/allauth/', login.KakaoLogin.as_view()),
]

это журнал сервера

$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
September 17, 2022 - 15:15:17
Django version 4.0.6, using settings 'project.settings.local'
Starting ASGI/Channels version 3.0.5 development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Forbidden: /dj-rest-auth/user/
HTTP GET /dj-rest-auth/user/ 403 [0.02, 127.0.0.1:49400]
process1
process2
process3
process4

есть точка, которая отправляет запрос на 'kakao/login/allauth' внутри функции 'kakao/authenticate', и именно здесь сервер останавливается. Вам это покажется странным, но все работало хорошо, пока я не применил канал.

На мой взгляд, серверу стало невозможно обрабатывать различные запросы, применяя канал. Но почему? я не понимаю этой причины пожалуйста, помогите мне

Вернуться на верх