Heroku Python Web进程无法在60秒内绑定到$ PORT - 不是显而易见的

时间:2016-06-28 20:43:13

标签: python heroku cherrypy

通过简单的解决方案,可以回答类似的问题。不要以为这是一样的。首先是我的代码然后是日志。我正在使用提供的PORT env变量,但我仍然遇到此错误。

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

1 个答案:

答案 0 :(得分:2)

好的,这个问题有几个问题。到目前为止,最常见的是不使用环境变量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())