我想将我的django项目部署到heroku。我的项目使用频道,因此我需要设置基于 ASGI 的环境。
我在heroku app中安装了两个附加组件。一个是 Heroku-postgresql ,另一个是 Heroku-redis 。
我有两个dynos请参考下图。
我在heroku git上成功推动了django项目。 $ git push heroku master
所以,我得到了网址。 demo-multichat.herokuapp.com
如果您访问该网址,则会遇到应用程序错误。
我使用$ heroku logs
获取了log msg。以下是日志消息。
2017-09-08T11:54:50.421663+00:00 app[web.1]: 2017-09-08 20:54:50,421 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:54:55.424117+00:00 app[web.1]: 2017-09-08 20:54:55,423 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:00.426387+00:00 app[web.1]: 2017-09-08 20:55:00,426 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:05.428815+00:00 app[web.1]: 2017-09-08 20:55:05,428 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:10.430511+00:00 app[web.1]: 2017-09-08 20:55:10,430 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:15.432112+00:00 app[web.1]: 2017-09-08 20:55:15,431 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:18.486722+00:00 heroku[worker.1]: State changed from crashed to starting
2017-09-08T11:55:20.434001+00:00 app[web.1]: 2017-09-08 20:55:20,433 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:22.996928+00:00 heroku[worker.1]: Starting process with command `python manage.py runworker`
2017-09-08T11:55:23.685971+00:00 heroku[worker.1]: State changed from starting to up
2017-09-08T11:55:25.435766+00:00 app[web.1]: 2017-09-08 20:55:25,435 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:27.264386+00:00 app[worker.1]: 2017-09-08 20:55:27,264 - INFO - runworker - Using single-threaded worker.
2017-09-08T11:55:27.264803+00:00 app[worker.1]: 2017-09-08 20:55:27,264 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisChannelLayer)
2017-09-08T11:55:27.265237+00:00 app[worker.1]: 2017-09-08 20:55:27,264 - INFO - worker - Listening on channels chat.receive, http.request, websocket.connect, websocket.disconnect, websocket.receive
2017-09-08T11:55:27.276810+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 484, in connect
2017-09-08T11:55:27.277217+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 541, in _connect
2017-09-08T11:55:27.277631+00:00 app[worker.1]: raise err
2017-09-08T11:55:27.276796+00:00 app[worker.1]: Traceback (most recent call last):
2017-09-08T11:55:27.277635+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 529, in _connect
2017-09-08T11:55:27.277992+00:00 app[worker.1]: sock.connect(socket_address)
2017-09-08T11:55:27.278042+00:00 app[worker.1]: ConnectionRefusedError: [Errno 111] Connection refused
2017-09-08T11:55:27.277199+00:00 app[worker.1]: sock = self._connect()
2017-09-08T11:55:27.278044+00:00 app[worker.1]:
2017-09-08T11:55:27.278045+00:00 app[worker.1]: During handling of the above exception, another exception occurred:
2017-09-08T11:55:27.278045+00:00 app[worker.1]:
2017-09-08T11:55:27.278049+00:00 app[worker.1]: Traceback (most recent call last):
2017-09-08T11:55:27.278050+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/client.py", line 667, in execute_command
2017-09-08T11:55:27.278455+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 610, in send_command
2017-09-08T11:55:27.278453+00:00 app[worker.1]: connection.send_command(*args)
2017-09-08T11:55:27.278858+00:00 app[worker.1]: self.send_packed_command(self.pack_command(*args))
2017-09-08T11:55:27.278862+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 585, in send_packed_command
2017-09-08T11:55:27.279107+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 489, in connect
2017-09-08T11:55:27.279104+00:00 app[worker.1]: self.connect()
2017-09-08T11:55:27.279337+00:00 app[worker.1]: redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
2017-09-08T11:55:27.279322+00:00 app[worker.1]: raise ConnectionError(self._error_message(e))
2017-09-08T11:55:27.279338+00:00 app[worker.1]:
2017-09-08T11:55:27.279339+00:00 app[worker.1]: During handling of the above exception, another exception occurred:
2017-09-08T11:55:27.279339+00:00 app[worker.1]:
2017-09-08T11:55:27.279340+00:00 app[worker.1]: Traceback (most recent call last):
2017-09-08T11:55:27.279340+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 484, in connect
2017-09-08T11:55:27.279538+00:00 app[worker.1]: sock = self._connect()
2017-09-08T11:55:27.279541+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 541, in _connect
2017-09-08T11:55:27.279757+00:00 app[worker.1]: raise err
2017-09-08T11:55:27.279760+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 529, in _connect
2017-09-08T11:55:27.279971+00:00 app[worker.1]: sock.connect(socket_address)
2017-09-08T11:55:27.279974+00:00 app[worker.1]: ConnectionRefusedError: [Errno 111] Connection refused
2017-09-08T11:55:27.279976+00:00 app[worker.1]:
2017-09-08T11:55:27.279977+00:00 app[worker.1]: During handling of the above exception, another exception occurred:
2017-09-08T11:55:27.279978+00:00 app[worker.1]:
2017-09-08T11:55:27.279991+00:00 app[worker.1]: Traceback (most recent call last):
2017-09-08T11:55:27.279993+00:00 app[worker.1]: File "manage.py", line 10, in <module>
2017-09-08T11:55:27.280072+00:00 app[worker.1]: execute_from_command_line(sys.argv)
2017-09-08T11:55:27.280083+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
2017-09-08T11:55:27.280251+00:00 app[worker.1]: utility.execute()
2017-09-08T11:55:27.280254+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
2017-09-08T11:55:27.280421+00:00 app[worker.1]: self.fetch_command(subcommand).run_from_argv(self.argv)
2017-09-08T11:55:27.280424+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
2017-09-08T11:55:27.280590+00:00 app[worker.1]: self.execute(*args, **cmd_options)
2017-09-08T11:55:27.280591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
2017-09-08T11:55:27.280762+00:00 app[worker.1]: output = self.handle(*args, **options)
2017-09-08T11:55:27.280763+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/channels/management/commands/runworker.py", line 83, in handle
2017-09-08T11:55:27.280878+00:00 app[worker.1]: worker.run()
2017-09-08T11:55:27.280879+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/channels/worker.py", line 87, in run
2017-09-08T11:55:27.280972+00:00 app[worker.1]: channel, content = self.channel_layer.receive_many(channels, block=True)
2017-09-08T11:55:27.280973+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/asgiref/base_layer.py", line 43, in receive_many
2017-09-08T11:55:27.282189+00:00 app[worker.1]: return self.receive(channels, block)
2017-09-08T11:55:27.282191+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/asgi_redis/core.py", line 215, in receive
2017-09-08T11:55:27.282191+00:00 app[worker.1]: result = connection.blpop(list_names, timeout=self.blpop_timeout)
2017-09-08T11:55:27.282192+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/client.py", line 1269, in blpop
2017-09-08T11:55:27.282193+00:00 app[worker.1]: return self.execute_command('BLPOP', *keys)
2017-09-08T11:55:27.282193+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/client.py", line 673, in execute_command
2017-09-08T11:55:27.282194+00:00 app[worker.1]: connection.send_command(*args)
2017-09-08T11:55:27.282195+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 610, in send_command
2017-09-08T11:55:27.282196+00:00 app[worker.1]: self.send_packed_command(self.pack_command(*args))
2017-09-08T11:55:27.282196+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 585, in send_packed_command
2017-09-08T11:55:27.282453+00:00 app[worker.1]: self.connect()
2017-09-08T11:55:27.282454+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/redis/connection.py", line 489, in connect
2017-09-08T11:55:27.282744+00:00 app[worker.1]: raise ConnectionError(self._error_message(e))
2017-09-08T11:55:27.282772+00:00 app[worker.1]: redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
2017-09-08T11:55:27.459143+00:00 heroku[worker.1]: State changed from up to crashed
2017-09-08T11:55:27.446333+00:00 heroku[worker.1]: Process exited with status 1
2017-09-08T11:55:10+00:00 app[heroku-redis]: source=REDIS sample#active-connections=2 sample#load-avg-1m=0.315 sample#load-avg-5m=0.21 sample#load-avg-15m=0.16 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664264kB sample#memory-free=11905356kB sample#memory-cached=961068kB sample#memory-redis=299032bytes sample#hit-rate=1 sample#evicted-keys=0
2017-09-08T11:55:30.437885+00:00 app[web.1]: 2017-09-08 20:55:30,437 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:35.439587+00:00 app[web.1]: 2017-09-08 20:55:35,439 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:40.441760+00:00 app[web.1]: 2017-09-08 20:55:40,441 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:45.443072+00:00 app[web.1]: 2017-09-08 20:55:45,442 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:50.444948+00:00 app[web.1]: 2017-09-08 20:55:50,444 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:55:55.446645+00:00 app[web.1]: 2017-09-08 20:55:55,446 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:00.449178+00:00 app[web.1]: 2017-09-08 20:56:00,448 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:05.450944+00:00 app[web.1]: 2017-09-08 20:56:05,450 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:10.452898+00:00 app[web.1]: 2017-09-08 20:56:10,452 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:15.456223+00:00 app[web.1]: 2017-09-08 20:56:15,456 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:20.457782+00:00 app[web.1]: 2017-09-08 20:56:20,457 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:25.459987+00:00 app[web.1]: 2017-09-08 20:56:25,459 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:30.461919+00:00 app[web.1]: 2017-09-08 20:56:30,461 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:08+00:00 app[heroku-redis]: source=REDIS sample#active-connections=2 sample#load-avg-1m=0.305 sample#load-avg-5m=0.24 sample#load-avg-15m=0.17 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664264kB sample#memory-free=11911660kB sample#memory-cached=961060kB sample#memory-redis=299032bytes sample#hit-rate=1 sample#evicted-keys=0
2017-09-08T11:56:35.463998+00:00 app[web.1]: 2017-09-08 20:56:35,463 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:40.466396+00:00 app[web.1]: 2017-09-08 20:56:40,466 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:45.467830+00:00 app[web.1]: 2017-09-08 20:56:45,467 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:50.469777+00:00 app[web.1]: 2017-09-08 20:56:50,469 ERROR Error trying to receive messages: NOAUTH Authentication required.
2017-09-08T11:56:55.471533+00:00 app[web.1]: 2017-09-08 20:56:55,471 ERROR Error trying to receive messages: NOAUTH Authentication required.
我怎么了?我想知道我是否正确设置了重要文件(asgi.py, wsgi.py, settings.py, manage.py, Procfile
)。
你能看看那些文件吗?我离开了我的项目github存储库。 repo
multichat / asgi.py,wsgi.py
设置/ dev.py,prod.py,settings.py
manage.py,Procfile
如果设置没问题,那有什么不对?感谢您的帮助。
答案 0 :(得分:0)
我相信您的redis设置可能有误,您可能错过了密码?
尝试将prod配置中的"hosts": [os.environ.get('REDIS_URL')]
更改为asgi_redis
。
推理:
我检查了https://devcenter.heroku.com/articles/heroku-redis#connecting-in-django,有密码配置,但我发现您使用的是"hosts": ["redis://:password@127.0.0.1:6379/0"]
,因此我转向https://github.com/django/asgi_redis,发现 FindValidSocket(Type){
let count=0;
while (count!==this.Max[Type]){
if(typeof(this.traitement[Type][count])==="undefined"){
return count;
}else{
count++;
}
}
return false;
}
是有效配置。< / p>