Websocket error in my consumers

I observed something interesting, in local the server is Daphne and in prod NGINX, even if I use NGINX to deploy my server, should it not put Daphne?

Uploading: image.png…

I’m sure that there’s an nginx configuration option available to allow the proxied server to supply the Server header, but unless your client is looking for that header to do something specific because of it, it’s not relevant.

locally in my data, it returned an error but I could still use the content, I have the impression that it is my configuration that has a problem, if it is not a problem of version, where would come the problem if not the configuration


You would have to examine every difference between your production and local environment. That’s why I recommended above that one of your options is to replicate your production evironment locally.

With everything that has been discussed recently, I don’t currently know what the issue is that you’re trying to resolve here. It would help me if you identify what is happening. You keep saying things like “it returned an error”, but you’re not providing any information about that error.

The problem is that normally I receive data from my webscoket (where it says error, look at the 2 images


I see these images, but I don’t see a problem. What’s the problem?

I don’t receive any data, you see in local there is a data, in production there is not

So what information is showing up on the server side identifying the source of the problem?

Or, phrasing this a different way, what are you expecting to have happen on the server that isn’t happening? What are you doing on the server to identify the source of the problem?

What logging have you added to assist this search?

When I type this command I get this sudo tail -F /var/log/syslog, I don’t know if it is this command to see what is happening on the server,

I didn’t create any record except the record in consumers, but I don’t get anything in my debug.log file

I also get this error when I type this command sudo less /var/log/nginx/error.log

2022/11/20 16:21:24 [error] 136673#136673: *66 recv() failed (104: Unknown error) while proxying upgraded connection, client:, server: *********, request: "GET /ws/ HTTP/1.1", upstream: "", host: "******

Ok, so we are talking about the same HubriseOrder as earlier.

At Websocket error in my consumers - #24 by KenWhitesell I identified three different approaches you could take to identify the root cause of this issue.

From what I’ve been reading here, it appears like you’ve tried the first, so you have two more things you can try at this point.

Hello, so I tried the second solution, I created pip3 freeze > requirements.txt, then I install them in production, it did not work, then I recreated a local environment with my git repository (the one that is linked to my project in production, it worked locally.

So for me it is not a problem of version, I have badly to configure my daphen.service, or my redis or even goods
sudo nano /etc/nginx/sites-available/apporder

Nope, it’s absolutely not a problem with your service files or redis or nginx. Don’t let yourself get distracted by these side topics. Those elements do not reach into your Python runtime environment. It’s strictly a Django/Channels/Third-party library issue.

You should be able to demonstrate that by replacing your consumer with a generic consumer (perhaps the one from the tutorial) just to verify that all these other components are functional.

Assuming that works (which I strongly believe should be the case), then you can start adding functionality back into the consumer to see where things break.

very good idea I had not thought of it, I will put in comment my consumers and create a simple one to see if it works, what tutorials are you talking about? Sorry I don’t remember

I’m referring to the original (“official”) Channels tutorial.

So I created a consumer that does not refer to HubriseOrder at any time, it is a simple consumer that I took from the official documentation and the error returns

Nov 21 14:25:31 django411onubuntu2204-s-1vcpu-1gb-amd-ams3-01 python[95787]:   File "/home/wahab/apporder/./myapp/consumers.py", line 14, in get_queryset
Nov 21 14:25:31 django411onubuntu2204-s-1vcpu-1gb-amd-ams3-01 python[95787]:     # #         logger = logging.getLogger('django')
Nov 21 14:25:31 django411onubuntu2204-s-1vcpu-1gb-amd-ams3-01 python[95787]: AttributeError: type object 'HubriseOrder' has no attribute 'filter'

(I did check that my file was updated with a cat myapp/consumers.py )

Did you stop and restart all the services?

Can you post the complete modified consumers.py here?

# from typing import Generic
# from myapp.models import HubriseOrder
# from myapp.serializers import HubriseOrderSerializer
# from djangochannelsrestframework import permissions
# from djangochannelsrestframework.generics import GenericAsyncAPIConsumer
# from djangochannelsrestframework.mixins import ListModelMixin
# from djangochannelsrestframework.observer import model_observer
# # import logging

# class HubriseOrderConsumer(ListModelMixin, GenericAsyncAPIConsumer):
#     def get_queryset(self, **kwargs):
# #         logger = logging.getLogger('django')
# #         logger.info((type(HubriseOrder.objects)))
#         return HubriseOrder.objects.filter(ascount=self.scope["user"]).exclude(status__in=['En attente', 'Rejeter', 'Compléter', 'new', 'Livraison échouer']).order_by('created_at')
#     serializer_class = HubriseOrderSerializer
#     permissions = (permissions.AllowAny,)

#     async def connect(self, **kwargs):
#         await self.model_change.subscribe()
#         await super().connect()

#     @model_observer(HubriseOrder)
#     async def model_change(self, message, observer=None, **kwargs):
#         await self.send_json(message)

#     @model_change.serializer
#     def model_serialize(self, instance, action, **kwargs):
#         return dict(data=HubriseOrderSerializer(instance=instance).data, action=action.value)
from channels.consumer import AsyncConsumer

class HubriseOrderConsumer(AsyncConsumer):

    async def websocket_connect(self, event):
        await self.send({
            "type": "websocket.accept",

    async def websocket_receive(self, event):
        await self.send({
            "type": "websocket.send",
            "text": event["text"],

I use this to reload my system

sudo systemctl restart gunicorn
sudo systemctl daemon-reload
sudo systemctl restart gunicorn.socket gunicorn.service
sudo nginx -t && sudo systemctl restart nginx

And you’re still getting the exact same error?

yes exactly the same mistake

If it’s the same error:

What other references do you have to either HubriseOrderConsumer or your consumers.py file in your project?

Obviously, you no longer have a get_queryset method at line 14 in this file, so either you’re not running the code you think you’re running (unlikely), or something else is trying to inject a get_queryset method into this class. (possible)

This means you’re going to need to dig through your entire project to try and find what might be doing this.