开发者社区> 问答> 正文

flask代码没有错误,但是运行报错,是什么原因

from flask import Flask

app=Flask(__name__)

@app.route("/",methods=["GET"])
def index():
    return "hello,world",200

if __name__=="__main__":
    app.run(host="0.0.0.0",port=5004)

报错如下

Traceback (most recent call last):
  File "b.py", line 10, in <module>
    app.run(host="0.0.0.0",port=5004)
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 922, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 1008, in run_simple
    inner()
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 957, in inner
    fd=fd,
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 781, in make_server
    host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 686, in __init__
    super().__init__(server_address, handler)  # type: ignore
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 48] Address already in use

展开
收起
道月芬1 2021-10-18 15:27:05 534 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载