You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FastAPI+Uvicorn项目8080端口ConnectionResetError问题求助

8080端口ConnectionResetError问题排查

客户端可连接服务端所有端口,仅8080端口例外。基于FastAPI+Uvicorn框架的Python项目,此前一个月8080端口正常可用,近期使用requests库或Postman向服务端发起请求时,会触发ConnectionResetError,其他测试过的端口均无异常。

测试代码

服务端代码

from fastapi import FastAPI

# Create an instance of the FastAPI class
app = FastAPI()

# Define a route for the root endpoint "/"
@app.get("/")
async def read_root():
    i = 1
    return {"message": "Hello, world!"}

# Run the FastAPI application using uvicorn server on port 8080
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)

客户端代码

import requests
response = requests.get(f"http://localhost:8080/")
if response.ok:
    print("No issues")
else:
    print(f"Some issue {response.text}")

触发的错误信息

Exception has occurred: ConnectionError
('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

File "/Users/SP/Documents/VSWorkspace/storage/testing/c1.py", line 2, in <module>
response = requests.get(f"http://localhost:8080/")
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

端口检查结果

执行lsof -i:8080未发现运行中的进程,但存在一条记录:
webfilter 26541 root 25u IPv6 0x5c28b320858b3bef 0t0 TCP localhost:57161->localhost:http-alt (CLOSED)

内容的提问来源于stack exchange,提问作者Sohan Patil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 07:03:32