Sunday, February 5, 2017

Re: Django-channels can't connect to websocket server. But when I am using redis I can't connect to my site at all.

I managed to run it somehow but now it says that the socket closed before it was able to connect and from the logs I got 
ERROR - worker - Error processing message with consumer play.consumers.ws_connect:

I am not sending any message from javascript. So I suppose the error is in ws_connect. The final error however is  
ValueError: invalid literal for int() with base 10: 'websocket.send!ICANvzjn'


Here is my ws_connect:
@channel_session_user_from_http
def ws_connect(message):
# message.reply_channel.send({'accept': True})

username = message.user.username
reply_channel_name = message.reply_channel.name

waiting_users = OnlineUsers.objects.all()
# If there are waiting users connect to one of them
if waiting_users:
user_topair = waiting_users.first()
pair = PairUsers()
pair.username_a = username
pair.username_b = user_topair.username
pair.reply_channel_a = reply_channel_name
pair.reply_channel_b = user_topair.reply_channel_name
pair.save()
print(user_topair)
user_topair.delete()

else:
# else put the user on the waiting list
OnlineUsers(username, reply_channel_name).save()
message.reply_channel.send({'message': "Please wait while we find a user to pair you with"})



неделя, 5 февруари 2017 г., 2:11:46 UTC+2, Andrew Godwin написа:
If you ever see "Unexpected response code: 200" it means that something between you and the server doesn't understand WebSockets. Given it's localhost in this case, have you installed channels and make sure it's in INSTALLED_APPS, then run `runserver`?

Andrew

On Sat, Feb 4, 2017 at 3:20 AM, Nikoleta Misheva <nith...@gmail.com> wrote:
When I use django-channels with reconnecting websocket without redis backend and try to connect to ws://localhost:8000/play it returns 
Error during WebSocket handshake: Unexpected response code: 200
But when I use the redis backend and even tho the workers are running and etc I can't connect to my site it just loads forever and doesn't even end up in connection timeout.
I would be glad if someone can help me. Here is the gist with my code because the files are too many and it would be hard to put them in here, sorry for the inconvenience.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/454151ae-1631-45df-881c-0dfdaf8f180f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6ae0deb8-3c2a-46cb-bb0f-13cc6efd02e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment