Daphne + Django Channels 在 Heroku 上给出错误 503
Daphne + Django Channels gives error 503 on Heroku
过去 2 天我一直在尝试让我的 Django Channels 应用程序在 Heroku 上运行,但似乎无法正常运行。我最近甚至无法 运行 该应用程序,但经过一番挖掘后,我设法启动了它。该应用程序在本地主机上运行良好。我从错误 404 到 500,现在是 504。我一直在尝试了解 Heroku 日志,但似乎找不到解决方案。希望有人能给我一个关于如何修复它的提示。
这是不同的文件和日志。
设置:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
},
},
}
要求:
Django==3.0.7
gunicorn==19.9.0
pytz==2019.3
sqlparse==0.3.0
whitenoise==5.0.1
tweepy==3.8.0
dj-database-url==0.5.0
psycopg2-binary==2.8.5
discord.py==1.3.3
requests==2.23.0
channels-redis==2.4.2
channels==2.4.0
daphne==2.5.0
asgi.py
import os
import django
from channels.routing import get_default_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'APPNAME.settings')
django.setup()
application = get_default_application()
过程文件:
web: daphne APPNAME.asgi:application --port $PORT --bind 0.0.0.0 -v2
Heroku 日志:
2020-06-09T14:57:15.403840+00:00 app[web.1]: 2020-06-09 14:57:15,403 DEBUG HTTP response complete for ['10.38.205.57', 33999]
2020-06-09T14:57:15.403926+00:00 app[web.1]: 10.38.205.57:33999 - - [09/Jun/2020:14:57:15] "GET /static/img/favicon.png" 200 10836
2020-06-09T14:57:15.400849+00:00 heroku[router]: at=info method=GET path="/static/img/favicon.png" host=www.domain.com request_id=fe8bd6bb-9050-4815-bf83-0b65cdb0b0cf fwd="90.90.83.191" dyno=web.1 connect=0ms service=7ms status=200 bytes=11090 protocol=https
2020-06-09T14:57:15.567171+00:00 app[web.1]: 2020-06-09 14:57:15,566 ERROR [Failure instance: Traceback: <class 'ValueError'>: No route found for path 'ws/panel/order/96eda/'.
2020-06-09T14:57:15.567180+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/autobahn/websocket/protocol.py:2847:processHandshake
2020-06-09T14:57:15.567181+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/txaio/tx.py:366:as_future
2020-06-09T14:57:15.567182+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/twisted/internet/defer.py:151:maybeDeferred
2020-06-09T14:57:15.567182+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/daphne/ws_protocol.py:83:onConnect
2020-06-09T14:57:15.567183+00:00 app[web.1]: --- <exception caught here> ---
2020-06-09T14:57:15.567183+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/twisted/internet/defer.py:151:maybeDeferred
2020-06-09T14:57:15.567183+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/daphne/server.py:200:create_application
2020-06-09T14:57:15.567184+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/routing.py:54:__call__
2020-06-09T14:57:15.567184+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/sessions.py:47:__call__
2020-06-09T14:57:15.567185+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/sessions.py:145:__call__
2020-06-09T14:57:15.567185+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/sessions.py:169:__init__
2020-06-09T14:57:15.567185+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/middleware.py:31:__call__
2020-06-09T14:57:15.567186+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/routing.py:150:__call__
2020-06-09T14:57:15.567258+00:00 app[web.1]: ]
2020-06-09T14:57:15.567533+00:00 app[web.1]: 2020-06-09 14:57:15,567 DEBUG Upgraded connection ['10.15.161.126', 32805] to WebSocket
2020-06-09T14:57:19.879740+00:00 app[web.1]: 2020-06-09 14:57:19,879 WARNING dropping connection to peer tcp4:10.15.161.126:32805 with abort=True: WebSocket opening handshake timeout (peer did not finish the opening handshake in time)
2020-06-09T14:57:19.880267+00:00 app[web.1]: 2020-06-09 14:57:19,880 DEBUG WebSocket closed for ['10.15.161.126', 32805]
2020-06-09T14:57:19.880376+00:00 app[web.1]: 10.15.161.126:32805 - - [09/Jun/2020:14:57:19] "WSDISCONNECT /ws/panel/order/96eda/" - -
2020-06-09T14:57:19.880503+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/ws/panel/order/96eda/" host=www.domain.com request_id=7b5b433b-c291-4994-8b5b-8e424447ce3e fwd="90.90.83.191" dyno=web.1 connect=0ms service=4319ms status=503 bytes=0 protocol=https
2020-06-09T14:56:44+00:00 app[heroku-redis]: source=REDIS addon=redis-cubed-69516 sample#active-connections=1 sample#load-avg-1m=0.165 sample#load-avg-5m=0.17 sample#load-avg-15m=0.155 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664256kB sample#memory-free=11266544kB sample#memory-cached=1033556kB sample#memory-redis=313968bytes sample#hit-rate=1 sample#evicted-keys=0
提前致谢。
发现我的错误,这是最愚蠢的错误。我的路由出错,输入 "wss/panel/order" 认为 wss 部分是我的协议。
过去 2 天我一直在尝试让我的 Django Channels 应用程序在 Heroku 上运行,但似乎无法正常运行。我最近甚至无法 运行 该应用程序,但经过一番挖掘后,我设法启动了它。该应用程序在本地主机上运行良好。我从错误 404 到 500,现在是 504。我一直在尝试了解 Heroku 日志,但似乎找不到解决方案。希望有人能给我一个关于如何修复它的提示。 这是不同的文件和日志。
设置:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
},
},
}
要求:
Django==3.0.7
gunicorn==19.9.0
pytz==2019.3
sqlparse==0.3.0
whitenoise==5.0.1
tweepy==3.8.0
dj-database-url==0.5.0
psycopg2-binary==2.8.5
discord.py==1.3.3
requests==2.23.0
channels-redis==2.4.2
channels==2.4.0
daphne==2.5.0
asgi.py
import os
import django
from channels.routing import get_default_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'APPNAME.settings')
django.setup()
application = get_default_application()
过程文件:
web: daphne APPNAME.asgi:application --port $PORT --bind 0.0.0.0 -v2
Heroku 日志:
2020-06-09T14:57:15.403840+00:00 app[web.1]: 2020-06-09 14:57:15,403 DEBUG HTTP response complete for ['10.38.205.57', 33999]
2020-06-09T14:57:15.403926+00:00 app[web.1]: 10.38.205.57:33999 - - [09/Jun/2020:14:57:15] "GET /static/img/favicon.png" 200 10836
2020-06-09T14:57:15.400849+00:00 heroku[router]: at=info method=GET path="/static/img/favicon.png" host=www.domain.com request_id=fe8bd6bb-9050-4815-bf83-0b65cdb0b0cf fwd="90.90.83.191" dyno=web.1 connect=0ms service=7ms status=200 bytes=11090 protocol=https
2020-06-09T14:57:15.567171+00:00 app[web.1]: 2020-06-09 14:57:15,566 ERROR [Failure instance: Traceback: <class 'ValueError'>: No route found for path 'ws/panel/order/96eda/'.
2020-06-09T14:57:15.567180+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/autobahn/websocket/protocol.py:2847:processHandshake
2020-06-09T14:57:15.567181+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/txaio/tx.py:366:as_future
2020-06-09T14:57:15.567182+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/twisted/internet/defer.py:151:maybeDeferred
2020-06-09T14:57:15.567182+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/daphne/ws_protocol.py:83:onConnect
2020-06-09T14:57:15.567183+00:00 app[web.1]: --- <exception caught here> ---
2020-06-09T14:57:15.567183+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/twisted/internet/defer.py:151:maybeDeferred
2020-06-09T14:57:15.567183+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/daphne/server.py:200:create_application
2020-06-09T14:57:15.567184+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/routing.py:54:__call__
2020-06-09T14:57:15.567184+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/sessions.py:47:__call__
2020-06-09T14:57:15.567185+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/sessions.py:145:__call__
2020-06-09T14:57:15.567185+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/sessions.py:169:__init__
2020-06-09T14:57:15.567185+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/middleware.py:31:__call__
2020-06-09T14:57:15.567186+00:00 app[web.1]: /app/.heroku/python/lib/python3.6/site-packages/channels/routing.py:150:__call__
2020-06-09T14:57:15.567258+00:00 app[web.1]: ]
2020-06-09T14:57:15.567533+00:00 app[web.1]: 2020-06-09 14:57:15,567 DEBUG Upgraded connection ['10.15.161.126', 32805] to WebSocket
2020-06-09T14:57:19.879740+00:00 app[web.1]: 2020-06-09 14:57:19,879 WARNING dropping connection to peer tcp4:10.15.161.126:32805 with abort=True: WebSocket opening handshake timeout (peer did not finish the opening handshake in time)
2020-06-09T14:57:19.880267+00:00 app[web.1]: 2020-06-09 14:57:19,880 DEBUG WebSocket closed for ['10.15.161.126', 32805]
2020-06-09T14:57:19.880376+00:00 app[web.1]: 10.15.161.126:32805 - - [09/Jun/2020:14:57:19] "WSDISCONNECT /ws/panel/order/96eda/" - -
2020-06-09T14:57:19.880503+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/ws/panel/order/96eda/" host=www.domain.com request_id=7b5b433b-c291-4994-8b5b-8e424447ce3e fwd="90.90.83.191" dyno=web.1 connect=0ms service=4319ms status=503 bytes=0 protocol=https
2020-06-09T14:56:44+00:00 app[heroku-redis]: source=REDIS addon=redis-cubed-69516 sample#active-connections=1 sample#load-avg-1m=0.165 sample#load-avg-5m=0.17 sample#load-avg-15m=0.155 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664256kB sample#memory-free=11266544kB sample#memory-cached=1033556kB sample#memory-redis=313968bytes sample#hit-rate=1 sample#evicted-keys=0
提前致谢。
发现我的错误,这是最愚蠢的错误。我的路由出错,输入 "wss/panel/order" 认为 wss 部分是我的协议。