python - Heroku Python Web 进程未能在 60 秒内绑定(bind)到 $PORT - 不是很明显

标签 python heroku cherrypy

好的,类似的问题之前已经用简单的解决方案回答过。别以为这个是一样的。首先是我的代码,然后是日志。我正在使用提供的 PORT 环境变量,但仍然收到此错误。

if __name__ == "__main__":
    import sys
    print( 'HELLO %s' % str(sys.argv[1]))
    #import os
    import os
    port = os.environ['PORT']
    print(port)
    cherrypy.config.update({
                        'server.socket_port': int(port),
                       })
    cherrypy.quickstart(House())

日志来了

2016-06-28T20:23:08.801989+00:00 app[web.1]: HELLO 33860
2016-06-28T20:23:08.802004+00:00 app[web.1]: 33860
2016-06-28T20:23:08.802471+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Listening for SIGTERM.
2016-06-28T20:23:08.802622+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Listening for SIGUSR1.
2016-06-28T20:23:08.802790+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Listening for SIGHUP.
2016-06-28T20:23:08.802942+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Bus STARTING
2016-06-28T20:23:08.803132+00:00 app[web.1]: CherryPy Checker:
2016-06-28T20:23:08.803139+00:00 app[web.1]: The Application mounted at '' has an empty config.
2016-06-28T20:23:08.803140+00:00 app[web.1]: 
2016-06-28T20:23:08.803640+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Started monitor thread '_TimeoutMonitor'.
2016-06-28T20:23:08.803919+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Started monitor thread 'Autoreloader'.
2016-06-28T20:23:08.955231+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Serving on http://127.0.0.1:33860
2016-06-28T20:23:08.955533+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Bus STARTED
2016-06-28T20:24:06.045442+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-28T20:24:06.045345+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

最佳答案

好吧,这个问题有几个问题。到目前为止,最常见的是不使用环境变量 PORT 中指定的端口。第二种是使用 localhost 或 127.0.0.1(或保留默认值)您指定的主机。将主机指定为 0.0.0.0 为我解决了这个问题。

if __name__ == "__main__":
    import sys
    print( 'HELLO %s' % str(sys.argv[1]))
    import os
    import os
    port = os.environ['PORT']
    print(port)
    cherrypy.config.update({
                            'server.socket_host': '0.0.0.0',
                            'server.socket_port': int(port),
                           })
    cherrypy.quickstart(House())

关于python - Heroku Python Web 进程未能在 60 秒内绑定(bind)到 $PORT - 不是很明显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38085948/

相关文章:

python - 当且仅当它在输入字符串中找到枚举时,如何创建删除等于子字符串的元素的正则表达式模式?

javascript - 在 Django 模板中访问 Javascript 变量

node.js - vue-cli-service : not found proplem on heroku? 如何解决

python - django.contrib.admin 类似于 cherrypy 的应用程序

python - 如何在 Azure ML Notebook 中使用 Blob 容器文件夹

python - raw_input在cpython源代码中哪里实现的?

python - CherryPy:405 Method Not allowed 指定的方法对此资源无效

python - CherryPy 网页表单 : checkboxes produces error when unchecked

node.js - 我的 API 请求很慢 - 从哪里开始调查导致延迟的原因?

ruby-on-rails - ExecJS::RuntimeError: SyntaxError: 意外的标记:运算符 (>) (行:22342,列:24,位置:826182)