Closed andy-io closed 8 years ago
Try making a websocket-events request directly to the Django app:
curl -i -H 'Content-Type: application/websocket-events' -d OPEN$'\r'$'\n' \
http://127.0.0.1:8000/users/socket
What response do you get?
this is the response i get:
HTTP/1.0 500 INTERNAL SERVER ERROR
Date: Sat, 26 Dec 2015 21:43:26 GMT
Server: WSGIServer/0.1 Python/2.7.10
X-Frame-Options: SAMEORIGIN
Content-Type: text/html
Hopefully the Django error page can tell us more. Set DEBUG = True
in settings.py and pipe the output of curl to a file (e.g. > out.html
) and view the file in a browser.
I saved the error page and this is the error i see:
Exception Type: RuntimeError
Exception Value:
You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/users/socket/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.
I added APPEND_SLASH=False in the settings.py and now i see a 404 error page.
A 404 error likely means a Django routing issue and not anything to do with django-grip. The error page should show the known routes so it should be easy to see why nothing matched.
Using the URLconf defined in sxk.urls, Django tried these URL patterns, in this order:
^users/ ^socket/$ [name='socket']
The current URL, users/socket, didn't match any of these.
Ah, because you've got a trailing slash in the pattern. Remove that and I bet it'll work.
I removed the trailing slash. Now its a csrf verification failed error. Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties. If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests.
should i change the route in pushpin to use without over_http ?
Progress! Now remove/comment-out the csrf middleware in settings.py. That's Django blocking POSTs that didn't come from a web form.
i added a csrf exepmt decorator and i suppose it should work, will post it in a while ;-)
working ^^ :-) i will have some more doubts still to push the data from a model into the browser using angular in front end. Let this thread be open. I will close it if i dont have any other doubts. Thanks for your wonderful support. Wishing you a happy new year mate :-)
Should i always access my site using the pushpin port or could i access it using django's port and let my angularjs app connect with pushpin ?
When i access my site using the first approach, i see some random get requests calling some unavaliable sass files in my server, looks like some malware attack. I am unable to figure out from where these requests are coming.
Second approach works fine without any problem.
Pushpin is designed to be able to front an entire web service. Whether you should run all requests through Pushpin or only the WebSocket stuff is a matter of how much you care about having a single base URL for everything.
The random GET requests seems strange. Is it reproducible?
ok got it, the random get requests seem to arise from my front front end components which i am still trying to figure out. They are not from push pin.
Is it possible to publish events when using websockets using django grip ? At the moment, all events are sent with type message.
What do you mean "sent with type message"?
i publish messages to a channel like this: publish("channel", WebSocketMessageFormat(message))
Examining this message in console as log shows that event type is message. How to send different types of events ?
Ah, you mean the argument sent to the onmessage handler? I believe the type is always "message" here and there is no way for the server to affect this. If you want to differentiate types of messages you'll need to include that information in the message data itself.
Thanks I did the same by sending it in the message itself. How to broadcast a message to all subscribed channels ?
Published messages are sent to all subscribers of a channel. If you want to broadcast to all connected clients, make sure all connections are also subscribed to a common channel (e.g. "all"), and then publish to that channel.
Super. I didnt think of an easy way of subscribing to a common channel. Thanks for your support and time.
Hi,
I am trying to open a websocket using pushpin in django. I am getting the following error.
route file is * 127.0.0.1:8000,over_http
I have started the pushpin proxy server, installed django grip, configured the settings file.
i have copied the example websocket view code in readme which is:
my url config to the view is
This urlconf is included in the root urlconf for the regex starting with 'users/'
In the client side, i use an example websocket connection opening code
clicking on the run websocket on the browser shows the first alert that browser supports websocket and then it shows the alert that the websocket connection is closed.
The local django dev server shows the following in the terminal:
[26/Dec/2015 16:56:17] "POST /users/socket HTTP/1.1" 500 81431
Could you help me figure out where I am going wrong ?
Thanks and regards, Andy