Django Channel Error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Django Channel Error

Maitreya Verma
I am following this tutorial to learn django channels. 
The following procedure was used :
  • Add the following code in settings.py
    redis_host=os.environ.get('REDIS_HOST','localhost')

    CHANNEL_LAYERS={
        "default":{
            "BACKEND":"asgi_redis.RedisChannelLayer",
            "CONFIG":{
                "hosts":[(redis_host),6379],
            },
            "ROUTING":'channelproj.routing.channel_routing',
        },
    }

  • Create a file routing.py and add the following code
    from channels import route
    # This function will display all messages received in the console
    def message_handler(message):
        print(message['text'])

    channel_routing = [
        route("websocket.receive", message_handler),
    ]

  • run server using python manage.py runserver and then try to connect to server using  ws.connect("ws://localhost:8000/")
I am getting the following error
websocket._exceptions.WebSocketBadStatusException: Handshake status 200

What can be the reason for this error and how can it be rectified?


--
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 [hidden email].
To post to this group, send email to [hidden email].
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/d560ebbb-242c-4481-b688-42e2d65c112a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Channel Error

Maitreya Verma
I am using Django 2.0, django-channels 0.7.0, asgi-redis 1.4.3

On Thursday, December 7, 2017 at 1:33:22 PM UTC+5:30, Maitreya Verma wrote:
I am following <a href="https://gearheart.io/blog/creating-a-chat-with-django-channels/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgearheart.io%2Fblog%2Fcreating-a-chat-with-django-channels%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF5SMAnRSLyFglz9OLHJ2iqB57nXA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgearheart.io%2Fblog%2Fcreating-a-chat-with-django-channels%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF5SMAnRSLyFglz9OLHJ2iqB57nXA&#39;;return true;">this tutorial to learn django channels. 
The following procedure was used :
  • Add the following code in settings.py
    redis_host=os.environ.get('REDIS_HOST','localhost')

    CHANNEL_LAYERS={
        "default":{
            "BACKEND":"asgi_redis.RedisChannelLayer",
            "CONFIG":{
                "hosts":[(redis_host),6379],
            },
            "ROUTING":'channelproj.routing.channel_routing',
        },
    }

  • Create a file routing.py and add the following code
    from channels import route
    # This function will display all messages received in the console
    def message_handler(message):
        print(message['text'])

    channel_routing = [
        route("websocket.receive", message_handler),
    ]

  • run server using python manage.py runserver and then try to connect to server using  ws.connect("ws://localhost:8000/")
I am getting the following error
websocket._exceptions.WebSocketBadStatusException: Handshake status 200

What can be the reason for this error and how can it be rectified?


--
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 [hidden email].
To post to this group, send email to [hidden email].
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/7a052cd8-7070-4606-8e94-b3a6ad4a4840%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Channel Error

Andrew Godwin-3
In reply to this post by Maitreya Verma
That error means you are not actually running a websocket-capable server. Did you add "channels" to INSTALLED_APPS?

Andrew

On Thu, Dec 7, 2017 at 12:03 AM, Maitreya Verma <[hidden email]> wrote:
I am following this tutorial to learn django channels. 
The following procedure was used :
  • Add the following code in settings.py
    redis_host=os.environ.get('REDIS_HOST','localhost')

    CHANNEL_LAYERS={
        "default":{
            "BACKEND":"asgi_redis.RedisChannelLayer",
            "CONFIG":{
                "hosts":[(redis_host),6379],
            },
            "ROUTING":'channelproj.routing.channel_routing',
        },
    }

  • Create a file routing.py and add the following code
    from channels import route
    # This function will display all messages received in the console
    def message_handler(message):
        print(message['text'])

    channel_routing = [
        route("websocket.receive", message_handler),
    ]

  • run server using python manage.py runserver and then try to connect to server using  ws.connect("ws://localhost:8000/")
I am getting the following error
websocket._exceptions.WebSocketBadStatusException: Handshake status 200

What can be the reason for this error and how can it be rectified?


--
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 [hidden email].
To post to this group, send email to [hidden email].
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/d560ebbb-242c-4481-b688-42e2d65c112a%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAFwN1uqzOi%2BqzANQL%2Bzw%2BZYYQM3YP_xNR631_%3DpDM_oYaej5%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Channel Error

Maitreya Verma
Yes it worked. I had not installed channels and not added it to INSTALLED_CHANNELS as well. Thanks Andrew!



On Thu, Dec 7, 2017 at 1:45 PM, Andrew Godwin <[hidden email]> wrote:
That error means you are not actually running a websocket-capable server. Did you add "channels" to INSTALLED_APPS?

Andrew

On Thu, Dec 7, 2017 at 12:03 AM, Maitreya Verma <[hidden email]> wrote:
I am following this tutorial to learn django channels. 
The following procedure was used :
  • Add the following code in settings.py
    redis_host=os.environ.get('REDIS_HOST','localhost')

    CHANNEL_LAYERS={
        "default":{
            "BACKEND":"asgi_redis.RedisChannelLayer",
            "CONFIG":{
                "hosts":[(redis_host),6379],
            },
            "ROUTING":'channelproj.routing.channel_routing',
        },
    }

  • Create a file routing.py and add the following code
    from channels import route
    # This function will display all messages received in the console
    def message_handler(message):
        print(message['text'])

    channel_routing = [
        route("websocket.receive", message_handler),
    ]

  • run server using python manage.py runserver and then try to connect to server using  ws.connect("ws://localhost:8000/")
I am getting the following error
websocket._exceptions.WebSocketBadStatusException: Handshake status 200

What can be the reason for this error and how can it be rectified?


--
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 [hidden email].
To post to this group, send email to [hidden email].
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/d560ebbb-242c-4481-b688-42e2d65c112a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/JDVTYOvAmXk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
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/CAFwN1uqzOi%2BqzANQL%2Bzw%2BZYYQM3YP_xNR631_%3DpDM_oYaej5%3DQ%40mail.gmail.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 [hidden email].
To post to this group, send email to [hidden email].
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/CABn9xLk8OqC_-6X1ZvMeSusQnSVdennt7wEaiJzH6iJ3QS0Ozw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.