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

运行FastAPI时出现Access Denied权限错误求助

FastAPI运行官方示例时出现Windows权限拒绝错误(WinError 5)

我刚开始使用FastAPI,运行官网提供的示例代码时遇到了Access Denied权限错误。我使用Windows系统,且拥有所有相关文件夹的访问权限,不清楚错误原因。

错误截图:
错误信息截图

错误栈信息:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 107, in spawn_main
    new_handle = reduction.duplicate(pipe_handle,
  File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\multiprocessing\reduction.py", line 79, in duplicate
    return _winapi.DuplicateHandle(
PermissionError: [WinError 5] Access is denied

使用的示例代码:

from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class Item(BaseModel):
    name: str
    price: float
    is_offer: Union[bool, None] = None


@app.get("/")
def read_root():
    return {"Hello": "world"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
    return {"item_name": item.name, "item_id": item_id, "item_price": item.price}

望各位能提供帮助,谢谢!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 18:40:32