简体   繁体   English

与工头开始的Socket.error:测试部署一个简单的烧瓶应用程序到Heroku

[英]Socket.error with foreman start: Tesing deploying a simple flask app to Heroku

The Problem 问题

socket.error: [Errno 98] Address already in use

What I'm doing 我在做什么

I'm testing a simple flask app with foreman start in my local environment. 我测试用一个简单的烧瓶应用foreman start在我的本地环境。 The app contains a few functions but its erroring here: 该应用程序包含一些功能,但它的错误在这里:

if __name__ == '__main__':
    app.run()

The full trace is shown below. 完整的跟踪如下所示。 I'm not sure what could wrong, or how the socket could already be in use on my local machine. 我不确定可能出现什么问题,或者我的本地机器上的套接字是如何使用的。 When I run the app with python runapp.py from the terminal everything works fine. 当我从终端运行带有python runapp.py的应用程序时,一切正常。

What I've tired. 我累了。

Heroku, flask, and python sockets? Heroku,烧瓶和蟒蛇插座?

Deploying Flask app to Heroku 将Flask应用程序部署到Heroku

following that last question I tired to change the port it runs on by using 在最后一个问题之后,我厌倦了改变它运行的端口

if __name__ == '__main__':    
    import os 
    port = int(os.environ.get('PORT', 5000)) 
    app.run(host='0.0.0.0', port=port)

But it didnt help. 但它没有帮助。 Any suggestions would be appreciated! 任何建议,将不胜感激! I'm new to Heroku so please let me know if there is anymore information I can provided to make solving this easier. 我是Heroku的新手所以请告诉我是否有更多的信息可以让我更容易解决这个问题。 Thanks! 谢谢!

Stack trace of error: 堆栈错误的痕迹:

        22:13:45 web.1  | started with pid 11121
        22:13:45 web.1  |  * Running on http://127.0.0.1:5000/
        22:13:45 web.1  | Traceback (most recent call last):
        22:13:45 web.1  |   File "Hunch/Hunch/hunchapp.py", line 49, in <module>
        22:13:45 web.1  |     app.run()
        22:13:45 web.1  |   File "/home/agconti/my_dev/github/Hunch/venv/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
        22:13:45 web.1  |     run_simple(host, port, self, **options)
        22:13:45 web.1  |   File "/home/agconti/my_dev/github/Hunch/venv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 706, in run_simple
        22:13:45 web.1  |     test_socket.bind((hostname, port))
        22:13:45 web.1  |   File "/usr/lib/python2.7/socket.py", line 224, in meth
        22:13:45 web.1  |     return getattr(self._sock,name)(*args)
        22:13:45 web.1  | socket.error: [Errno 98] Address already in use
        22:13:45 web.1  | exited with code 1
        22:13:45 system | sending SIGTERM to all processes

Soultion: Soultion:

from terminal: 从终端:

heroku config:add PORT=33507

Then change your app to: 然后将您的应用更改为:

if __name__ == '__main__':
        import os  
        port = int(os.environ.get('PORT', 33507)) 
        app.run(host='0.0.0.0', port=port)

It seems that heroku reserves flask's default port for its own purposes. 似乎heroku为了自己的目的保留了烧瓶的默认端口。 A detailed discussion can be found here: Deploying Flask app to Heroku . 可在此处找到详细讨论:将Flask应用程序部署到Heroku

When you terminate the flask application, use "Control + C." 终止烧瓶应用程序时,请使用“Control + C”。 If you use "Control + Z" it will leave the remaining report activate for some reason... I don't know why, but this seems to be the case for me in Debian (wheezy). 如果您使用“Control + Z”,它会因为某些原因而将剩余的报告激活...我不知道为什么,但在Debian(wheezy)中我似乎就是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM