7

I'm making an example from the documentation Django channels and it works great!

I see in the logs

HTTP GET /chat/lobby/ 200 [0.00, 127.0.0.1:43164] WebSocket HANDSHAKING /ws/chat/lobby/ [127.0.0.1:43168] WebSocket CONNECT /ws/chat/lobby/ [127.0.0.1:43168] 

however I can't connect with the wscat client

andrey@andrey-desktop:~$ wscat -c "ws://127.0.0.1:8000/ws/chat/lobby/" error: Unexpected server response: 403 

or postman - postman disconnect

I see in the logs on unsuccessful attempts

WebSocket HANDSHAKING /ws/chat/lobby/ [127.0.0.1:43232] WebSocket REJECT /ws/chat/lobby/ [127.0.0.1:43232] WebSocket DISCONNECT /ws/chat/lobby/ [127.0.0.1:43232] 

How do I make connectivity from other clients, not just from the javascript/html page?

2 Answers 2

14

Check if you have set AllowedHostsOriginValidator in asgi.py. If you do, you need to send Origin in your headers. If localhost, Origin is http://127.0.0.1:8000.

Sign up to request clarification or add additional context in comments.

Comments

0

As Mark stated here: https://stackoverflow.com/a/74761272/15618264

Your server will reject WS connections if AllowedHostsOriginValidator is set in your application.

Whatever your server is, an IP address or domain, you need to pass an Origin header with your request.

In Postman, go to the headers, type in Origin, pass either the domain name or the IP address with the scheme (http, https).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.