I’m sorry, I’m not going to try to validate or debug “obfuscated” data. If you cannot share the actual values, I’m unable to help further.
Please show the full response, both the headers and the content.
(What you’ve got looks right, so I’m either overlooking something or there’s something else going on here.)
There are no response headers on postman returned only request headers, tried using the logs but this all I get:
Could find the logs from ‘systemctl status daphne.service’:
so I started and stopped ‘daphne -b 0.0.0.0 -p 8001 taskitly.asgi:application’ just to get the logs.
Hmmm… I find it interesting that it’s reporting connections on /chat/
but your url shows notification/
.
I wonder if this is related to this note in the URLRouter docs:
Please note that
URLRouter
nesting will not work properly withpath()
routes if inner routers are wrapped by additional middleware. See Issue #1428.
If this situation is related to that, the issue doesn’t have anything to do with the Host header, but is actually related to using the path
function in a router with the extra middleware. That seems to match the symptoms here, and you could verify this by making the appropriate changes of the urls from path
to re_path
. (I’m not sure I’m reading this correctly, but the pattern seems to fit the symptoms you’re reporting.)
No, the log is bigger that what I could screenshot in one page, the notification log in still under.
So what are you seeing in the logs for these requests?
That’s all the log about these requests from the ‘daphne -b 0.0.0.0 -p 8001 taskitly.asgi:application’ logs from daphne.service is static but shows error requests after I remove the ‘ALLOWHOSTVALIDATOR’
Ok, at this point I’d try setting DEBUG=True in your settings and running Daphne with the -v 3
parameter on the command line just to try to gather more information.
I’d probably also want to get a basic script running to give me a second path for testing. (I don’t know postman well enough to know what it’s doing for websockets, or what exactly it’s sending.)
(This is in addition to trying the path
statement changes outlined above.)
I tried setting DEBUG=True and changed asgi file
(upload://rVrTby1FzoPSHIKmprb9djyeWzj.png)
Here’s the log from the daphne command
I know you said that if you remove the AllowedHostsOriginValidator
it works.
What happens if you remove the TokenAuthMiddleware
instead of the AllowedHostsOriginValidator
middlleware? There’s a possibility that there’s some type of conflict between those two middleware packages.
I removed the TokenAuthMiddleware instead but it still refuses the socket connection.
Side note 1: Are you remembering to restart your daphne service after every change? Unlike runserver, daphne does not auto-reload on changes.
I’ve just set up a copy of the Django/Channels tutorial on a site, and have run the basic test with Postman, and it connects without an issue. One of the things I learned is that the name of the header to be sent from the browser is “Origin” and not “Host” - if I do that, then Daphne allows the connection. (And its format is http://domain:port
)
I always remember to restart daphne, daemon-reload and nginx after changes.
So I’ll try to change the header in nginx conf.
Not in nginx - in Postman (if that’s what you’re still trying to use for this test.)
Its connected!
Thanks alot.
I’m having issues connecting to the sockets from the Browser.
var ws_scheme = window.location.protocol === "https:" ? "wss" : "ws";
var wsPath = ws_scheme + '://' + "taskitly.com" + ":8001/notification/";
var public_chat_socket = new WebSocket(wsPath);
public_chat_socket.onopen = function(event) {
var token = "a1705ce8ae02eb5dc4ca63cf93e95f8b97bd4094";
public_chat_socket.send(JSON.stringify({
"type": "auth",
"token": token
}));
};
public_chat_socket.onmessage = function(message){
var data = JSON.parse(message.data)
displayChatroomloadingSpinner(data.display_progress_bar)
if(data.join){
getRoomChatMessages()
}
if(data.error){
showClientErrorModal(data.message)
}
if(data.msg_type== 0){
appendChatMessage(data, true, true)
}
if(data.msg_type == 1){
setConnectUsersCount(data.connected_user_count)
console.log("msg_type triggered")
}
if(data.messages_payload){
handleMessagesPayload(data.messages, data.new_page_number)
}
};
If you can share how you connected with yours.