django channels on heroku hosting












1















Since I cant use redis I used the other channel layer that is
InMemoryChannelLayer



WSGI_APPLICATION = 'django_analytics.wsgi.application'
ASGI_APPLICATION = "django_analytics.routings.application"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer",
"CONFIG": {
},
},
}


I deployed it, on heroku but I am getting error




(index):9 WebSocket connection to
'wss://mkmnim.herokuapp.com/ws/chat/page/' failed: Error during
WebSocket handshake: Unexpected response code: 404




I got it working at my local server but I am not able to do the same in hosting it online,Also will I have to do something related to daphne ?
Initially I used redis and ran redis server locally but while hosting redis setup was paid so I choose InMemoryChannelLayer
(channels without channel layer or any other free hosting)



so what should I do ?



django_analytics.routings.py



from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from view_analytics import routing

application = ProtocolTypeRouter({
# Empty for now (http->django views is added by default)
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})


view_analytics.routings.py



from django.conf.urls import url

from . import consumers

websocket_urlpatterns = [
url(r'^ws/chat/room/$', consumers.ChatConsumer),
url(r'^ws/chat/page/$', consumers.PageConsumer),

]


page.html



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
let chatSocket = new WebSocket(
'wss://' + window.location.host +
'/ws/chat/' + 'page' + '/');

chatSocket.onmessage = function(e) {
const data = JSON.parse(e.data);
const message = data['message'];
console.log("message is"+ message)
};

chatSocket.onclose = function(e) {
console.error('Chat socket closed unexpectedly');
};
</script>

</body>
</html>


edit 1:
added heroku logs as well




2018-11-13T08:12:14.240908+00:00 heroku[router]: at=info method=GET
path="/view_analytics/page_check/" host=mkmnim.herokuapp.com
request_id=93802d36-fece-47b0-9e91-7f453d891f00 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=60ms status=200 bytes=726
protocol=https 2018-11-13T08:12:14.240275+00:00 app[web.1]:
10.41.198.116 - - [13/Nov/2018:08:12:14 +0000] "GET /view_analytics/page_check/ HTTP/1.1" 200 536 "-" "Mozilla/5.0 (X11;
Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/69.0.3497.81 Safari/537.36" 2018-11-13T08:12:15.342043+00:00
heroku[router]: at=info method=GET path="/ws/chat/page/"
host=mkmnim.herokuapp.com
request_id=c2f225eb-1f88-4417-87fe-281b6dd6fd51 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=7ms status=404 bytes=2534
protocol=https 2018-11-13T08:12:15.340615+00:00 app[web.1]: Not Found:
/ws/chat/page/ 2018-11-13T08:12:15.341106+00:00 app[web.1]:
10.168.81.123 - - [13/Nov/2018:08:12:15 +0000] "GET /ws/chat/page/ HTTP/1.1" 404 2351 "-" "Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81
Safari/537.36"











share|improve this question

























  • Can you show your frontend websocket Initialization code?

    – Raja Simon
    Nov 13 '18 at 7:44











  • edited,added html :-)

    – Nimish Bansal
    Nov 13 '18 at 7:44













  • Please clarify few details first. If this works in local then it will also works in heroku and it's nothing to do with InMemoryChannelLayer. Can you hard refresh your local browser and try to access the page in local server address?

    – Raja Simon
    Nov 13 '18 at 7:54











  • yes its working in local server.

    – Nimish Bansal
    Nov 13 '18 at 7:57











  • Okay. Please include the heroku logs if possible.

    – Raja Simon
    Nov 13 '18 at 8:06
















1















Since I cant use redis I used the other channel layer that is
InMemoryChannelLayer



WSGI_APPLICATION = 'django_analytics.wsgi.application'
ASGI_APPLICATION = "django_analytics.routings.application"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer",
"CONFIG": {
},
},
}


I deployed it, on heroku but I am getting error




(index):9 WebSocket connection to
'wss://mkmnim.herokuapp.com/ws/chat/page/' failed: Error during
WebSocket handshake: Unexpected response code: 404




I got it working at my local server but I am not able to do the same in hosting it online,Also will I have to do something related to daphne ?
Initially I used redis and ran redis server locally but while hosting redis setup was paid so I choose InMemoryChannelLayer
(channels without channel layer or any other free hosting)



so what should I do ?



django_analytics.routings.py



from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from view_analytics import routing

application = ProtocolTypeRouter({
# Empty for now (http->django views is added by default)
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})


view_analytics.routings.py



from django.conf.urls import url

from . import consumers

websocket_urlpatterns = [
url(r'^ws/chat/room/$', consumers.ChatConsumer),
url(r'^ws/chat/page/$', consumers.PageConsumer),

]


page.html



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
let chatSocket = new WebSocket(
'wss://' + window.location.host +
'/ws/chat/' + 'page' + '/');

chatSocket.onmessage = function(e) {
const data = JSON.parse(e.data);
const message = data['message'];
console.log("message is"+ message)
};

chatSocket.onclose = function(e) {
console.error('Chat socket closed unexpectedly');
};
</script>

</body>
</html>


edit 1:
added heroku logs as well




2018-11-13T08:12:14.240908+00:00 heroku[router]: at=info method=GET
path="/view_analytics/page_check/" host=mkmnim.herokuapp.com
request_id=93802d36-fece-47b0-9e91-7f453d891f00 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=60ms status=200 bytes=726
protocol=https 2018-11-13T08:12:14.240275+00:00 app[web.1]:
10.41.198.116 - - [13/Nov/2018:08:12:14 +0000] "GET /view_analytics/page_check/ HTTP/1.1" 200 536 "-" "Mozilla/5.0 (X11;
Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/69.0.3497.81 Safari/537.36" 2018-11-13T08:12:15.342043+00:00
heroku[router]: at=info method=GET path="/ws/chat/page/"
host=mkmnim.herokuapp.com
request_id=c2f225eb-1f88-4417-87fe-281b6dd6fd51 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=7ms status=404 bytes=2534
protocol=https 2018-11-13T08:12:15.340615+00:00 app[web.1]: Not Found:
/ws/chat/page/ 2018-11-13T08:12:15.341106+00:00 app[web.1]:
10.168.81.123 - - [13/Nov/2018:08:12:15 +0000] "GET /ws/chat/page/ HTTP/1.1" 404 2351 "-" "Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81
Safari/537.36"











share|improve this question

























  • Can you show your frontend websocket Initialization code?

    – Raja Simon
    Nov 13 '18 at 7:44











  • edited,added html :-)

    – Nimish Bansal
    Nov 13 '18 at 7:44













  • Please clarify few details first. If this works in local then it will also works in heroku and it's nothing to do with InMemoryChannelLayer. Can you hard refresh your local browser and try to access the page in local server address?

    – Raja Simon
    Nov 13 '18 at 7:54











  • yes its working in local server.

    – Nimish Bansal
    Nov 13 '18 at 7:57











  • Okay. Please include the heroku logs if possible.

    – Raja Simon
    Nov 13 '18 at 8:06














1












1








1








Since I cant use redis I used the other channel layer that is
InMemoryChannelLayer



WSGI_APPLICATION = 'django_analytics.wsgi.application'
ASGI_APPLICATION = "django_analytics.routings.application"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer",
"CONFIG": {
},
},
}


I deployed it, on heroku but I am getting error




(index):9 WebSocket connection to
'wss://mkmnim.herokuapp.com/ws/chat/page/' failed: Error during
WebSocket handshake: Unexpected response code: 404




I got it working at my local server but I am not able to do the same in hosting it online,Also will I have to do something related to daphne ?
Initially I used redis and ran redis server locally but while hosting redis setup was paid so I choose InMemoryChannelLayer
(channels without channel layer or any other free hosting)



so what should I do ?



django_analytics.routings.py



from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from view_analytics import routing

application = ProtocolTypeRouter({
# Empty for now (http->django views is added by default)
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})


view_analytics.routings.py



from django.conf.urls import url

from . import consumers

websocket_urlpatterns = [
url(r'^ws/chat/room/$', consumers.ChatConsumer),
url(r'^ws/chat/page/$', consumers.PageConsumer),

]


page.html



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
let chatSocket = new WebSocket(
'wss://' + window.location.host +
'/ws/chat/' + 'page' + '/');

chatSocket.onmessage = function(e) {
const data = JSON.parse(e.data);
const message = data['message'];
console.log("message is"+ message)
};

chatSocket.onclose = function(e) {
console.error('Chat socket closed unexpectedly');
};
</script>

</body>
</html>


edit 1:
added heroku logs as well




2018-11-13T08:12:14.240908+00:00 heroku[router]: at=info method=GET
path="/view_analytics/page_check/" host=mkmnim.herokuapp.com
request_id=93802d36-fece-47b0-9e91-7f453d891f00 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=60ms status=200 bytes=726
protocol=https 2018-11-13T08:12:14.240275+00:00 app[web.1]:
10.41.198.116 - - [13/Nov/2018:08:12:14 +0000] "GET /view_analytics/page_check/ HTTP/1.1" 200 536 "-" "Mozilla/5.0 (X11;
Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/69.0.3497.81 Safari/537.36" 2018-11-13T08:12:15.342043+00:00
heroku[router]: at=info method=GET path="/ws/chat/page/"
host=mkmnim.herokuapp.com
request_id=c2f225eb-1f88-4417-87fe-281b6dd6fd51 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=7ms status=404 bytes=2534
protocol=https 2018-11-13T08:12:15.340615+00:00 app[web.1]: Not Found:
/ws/chat/page/ 2018-11-13T08:12:15.341106+00:00 app[web.1]:
10.168.81.123 - - [13/Nov/2018:08:12:15 +0000] "GET /ws/chat/page/ HTTP/1.1" 404 2351 "-" "Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81
Safari/537.36"











share|improve this question
















Since I cant use redis I used the other channel layer that is
InMemoryChannelLayer



WSGI_APPLICATION = 'django_analytics.wsgi.application'
ASGI_APPLICATION = "django_analytics.routings.application"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer",
"CONFIG": {
},
},
}


I deployed it, on heroku but I am getting error




(index):9 WebSocket connection to
'wss://mkmnim.herokuapp.com/ws/chat/page/' failed: Error during
WebSocket handshake: Unexpected response code: 404




I got it working at my local server but I am not able to do the same in hosting it online,Also will I have to do something related to daphne ?
Initially I used redis and ran redis server locally but while hosting redis setup was paid so I choose InMemoryChannelLayer
(channels without channel layer or any other free hosting)



so what should I do ?



django_analytics.routings.py



from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from view_analytics import routing

application = ProtocolTypeRouter({
# Empty for now (http->django views is added by default)
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})


view_analytics.routings.py



from django.conf.urls import url

from . import consumers

websocket_urlpatterns = [
url(r'^ws/chat/room/$', consumers.ChatConsumer),
url(r'^ws/chat/page/$', consumers.PageConsumer),

]


page.html



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
let chatSocket = new WebSocket(
'wss://' + window.location.host +
'/ws/chat/' + 'page' + '/');

chatSocket.onmessage = function(e) {
const data = JSON.parse(e.data);
const message = data['message'];
console.log("message is"+ message)
};

chatSocket.onclose = function(e) {
console.error('Chat socket closed unexpectedly');
};
</script>

</body>
</html>


edit 1:
added heroku logs as well




2018-11-13T08:12:14.240908+00:00 heroku[router]: at=info method=GET
path="/view_analytics/page_check/" host=mkmnim.herokuapp.com
request_id=93802d36-fece-47b0-9e91-7f453d891f00 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=60ms status=200 bytes=726
protocol=https 2018-11-13T08:12:14.240275+00:00 app[web.1]:
10.41.198.116 - - [13/Nov/2018:08:12:14 +0000] "GET /view_analytics/page_check/ HTTP/1.1" 200 536 "-" "Mozilla/5.0 (X11;
Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/69.0.3497.81 Safari/537.36" 2018-11-13T08:12:15.342043+00:00
heroku[router]: at=info method=GET path="/ws/chat/page/"
host=mkmnim.herokuapp.com
request_id=c2f225eb-1f88-4417-87fe-281b6dd6fd51 fwd="47.31.181.82"
dyno=web.1 connect=1ms service=7ms status=404 bytes=2534
protocol=https 2018-11-13T08:12:15.340615+00:00 app[web.1]: Not Found:
/ws/chat/page/ 2018-11-13T08:12:15.341106+00:00 app[web.1]:
10.168.81.123 - - [13/Nov/2018:08:12:15 +0000] "GET /ws/chat/page/ HTTP/1.1" 404 2351 "-" "Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81
Safari/537.36"








python django django-channels






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 8:14







Nimish Bansal

















asked Nov 13 '18 at 7:35









Nimish BansalNimish Bansal

763417




763417













  • Can you show your frontend websocket Initialization code?

    – Raja Simon
    Nov 13 '18 at 7:44











  • edited,added html :-)

    – Nimish Bansal
    Nov 13 '18 at 7:44













  • Please clarify few details first. If this works in local then it will also works in heroku and it's nothing to do with InMemoryChannelLayer. Can you hard refresh your local browser and try to access the page in local server address?

    – Raja Simon
    Nov 13 '18 at 7:54











  • yes its working in local server.

    – Nimish Bansal
    Nov 13 '18 at 7:57











  • Okay. Please include the heroku logs if possible.

    – Raja Simon
    Nov 13 '18 at 8:06



















  • Can you show your frontend websocket Initialization code?

    – Raja Simon
    Nov 13 '18 at 7:44











  • edited,added html :-)

    – Nimish Bansal
    Nov 13 '18 at 7:44













  • Please clarify few details first. If this works in local then it will also works in heroku and it's nothing to do with InMemoryChannelLayer. Can you hard refresh your local browser and try to access the page in local server address?

    – Raja Simon
    Nov 13 '18 at 7:54











  • yes its working in local server.

    – Nimish Bansal
    Nov 13 '18 at 7:57











  • Okay. Please include the heroku logs if possible.

    – Raja Simon
    Nov 13 '18 at 8:06

















Can you show your frontend websocket Initialization code?

– Raja Simon
Nov 13 '18 at 7:44





Can you show your frontend websocket Initialization code?

– Raja Simon
Nov 13 '18 at 7:44













edited,added html :-)

– Nimish Bansal
Nov 13 '18 at 7:44







edited,added html :-)

– Nimish Bansal
Nov 13 '18 at 7:44















Please clarify few details first. If this works in local then it will also works in heroku and it's nothing to do with InMemoryChannelLayer. Can you hard refresh your local browser and try to access the page in local server address?

– Raja Simon
Nov 13 '18 at 7:54





Please clarify few details first. If this works in local then it will also works in heroku and it's nothing to do with InMemoryChannelLayer. Can you hard refresh your local browser and try to access the page in local server address?

– Raja Simon
Nov 13 '18 at 7:54













yes its working in local server.

– Nimish Bansal
Nov 13 '18 at 7:57





yes its working in local server.

– Nimish Bansal
Nov 13 '18 at 7:57













Okay. Please include the heroku logs if possible.

– Raja Simon
Nov 13 '18 at 8:06





Okay. Please include the heroku logs if possible.

– Raja Simon
Nov 13 '18 at 8:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275996%2fdjango-channels-on-heroku-hosting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275996%2fdjango-channels-on-heroku-hosting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation