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

runtime error TypeError: __call__() missing 2 required positional arguments: 'receive' and 'send' #366

Closed
harshilsuthar opened this issue Apr 7, 2021 · 9 comments

Comments

@harshilsuthar
Copy link

I was following the django-channels document and create a new conda env with python, Django and channels. there is no issue with dependency.

when i add 'channels' in installed apps then call view i got TypeError: call() missing 2 required positional arguments: 'receive' and 'send'
internal server error (500)

Screenshot from 2021-04-07 18-16-25

Screenshot from 2021-04-07 18-17-41

I don't know what to do

@adamchainz
Copy link
Sponsor Member

Conda may not install matching versions correctly. Did you use pip to install?

@harshilsuthar
Copy link
Author

Conda may not install matching versions correctly. Did you use pip to install?

thank you very much, it helped.
I have created a conda env with python and install channels using pip.

@Lukas-drz
Copy link

image
Hello, I have the same issue, can someone help me please ?
I'm stuck all day long...

@carltongibson
Copy link
Member

Maybe you forgot an as_asgi() on your consumers?

@Lukas-drz
Copy link

Lukas-drz commented Jan 18, 2023

from channels.generic.websocket import AsyncWebsocketConsumer
import json
from django.urls import path, re_path

class NotificationConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        # Vérifier l'authentification ici
        await self.accept()
        await self.channel_layer.group_add("notifications", self.channel_name)
        await self.send(text_data=json.dumps({
            'type': 'connected',
            'message': 'Connecté avec succès'
        }))

    async def disconnect(self, close_code):
        await self.channel_layer.group_discard("notifications", self.channel_name)

    async def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']
        # Traiter les données envoyées par le script ici
        await self.channel_layer.group_send(
            "notifications",
            {
                'type': 'notification_message',
                'message': message
            }
        )

websocket_urlpatterns = [
    path("ws", NotificationConsumer.as_asgi()),
]

This is my consummers.py

@carltongibson
Copy link
Member

I think you need to check all your versions.

TypeError: NotificationConsumer () missing 2 required positional arguments: 'receive' and 'send'

This looks like trying to instantiate a legacy application, implying an out-of-date Channels (or asgiref, or ...)

@Lukas-drz
Copy link

image
It is very strange because I'm using the latest ones...

@carltongibson
Copy link
Member

If you put a minimal reproduce in a sample project and open a fresh issue I can have a look.

(Can't say much from fragments and screenshots alone)

@Lenvia
Copy link

Lenvia commented May 23, 2023

image It is very strange because I'm using the latest ones...

I had the same issue and I tried restoring channels back to version3 and it worked.
pip install channels==3
But it seems to have some compatibility issues with django 4.0, like AuthMiddlewareStack.

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

5 participants