【发布时间】:2015-12-24 21:18:17
【问题描述】:
我最近更新了我的应用程序并尝试运行它,并收到以下关于“地址已在使用中”的错误。这是什么意思,我该如何解决?
Traceback (most recent call last):
File "/home/ubuntu/workspace/app.py", line 11, in <module>
app.run(host = os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT',8080)))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 687, in run_simple
inner()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 653, in inner
fd=fd).serve_forever()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 557, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 467, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
【问题讨论】:
-
这意味着有另一个服务正在使用该端口(在这种情况下为
8080)。可能是因为您忘记关闭另一个正在运行的 Flask 应用程序,它正在使用8080端口。 -
@KevinGuan 但我只部署了一个烧瓶应用程序:/
-
address already in use 表示服务器无法启动,因为另一个服务器在该端口上运行。检查您的程序是否已经运行,如果已经运行,则终止它。您还可以在 Windows 系统上使用 tcpview 查看活动的 tcp 服务器。
-
@user119264:嗯,你可以使用
nmap或netcat来检查哪个程序正在使用该端口。这是另一个问题,接受的答案是使用netcat,检查一下:unix.stackexchange.com/questions/106561/… -
改成 app.run(host=os.getenv('IP',0.0.0.0'),port=int(os.getenv('PORT',5000)))