推荐 最新
中年复健狗

fastapi 的 TestClient 的 delete 方法如何传递请求体?

接口 @meta.delete('', summary='删除指定母本', description='在请求体中传递一系列 meta_uuid, 返回已删除的母本的 meta_uuid', response_model=list[str]) def delete_meta( meta_uuids: list[str] ): pass 单元测试 client = TestClient(app) response = client.delete( f'/meta', json=[ f'{meta_uuid}' ] ) 但是报错了 Traceback (most recent call last): File "/Users/ponponon/Desktop/code/work/vddb/svddb_api/testing/apps/test_meta.py", line 121, in test_collection_meta_001 response = client.delete( TypeError: TestClient.delete() got an unexpected keyword argument 'json' 看了一下这个函数签名不支持 json 或者 data 参数 "图片.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250112/d4f38f397e4fc1214c99170c0f958cc5.png) 相比之下,requests 的 delete 是支持的传递 json 或者 data 的 怎么办?

13
1
0
浏览量331
今天吃什么你说吧

FastAPI中使用绝对地址,但是无法引用,为什么?

我在fastapi里使用绝对地址引入一个类,会报错?为什么呢,我看别人都是可以的 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240924/bb938be8630ff51caecd3dc7db5bcb99.png) 百度过很多了,都没解决,有大佬帮忙看看吗?

0
1
0
浏览量163
D_Y_大师

fastapi 能做网页棋牌类游戏吗? 如象棋,五子棋,掼蛋等类型的后端?

fastapi 能做网页棋牌类游戏吗? 如象棋,五子棋,掼蛋等类型的后端。 几百人在线。 与django相比优势如何? 如果不合适。做这类网页游戏用什么语言好? go node.js ?谢谢

0
1
0
浏览量123
代码大师

FastAPI 静态文件 MIME 类型返回错误导致 ESM 报错 Strict MIME type checking?

同样一个Web应用。家里使用正常。复制到公司电脑启动后访问就报错。 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec. Chrome/Firefox都这样。 用fastapi写的。代码文件都是复制过去的。 app.mount("/static", StaticFiles(directory="static"), name="static") app.mount("/main/assets", StaticFiles(directory="static/assets"), name="static") @app.get("/") async def redirect_to_static(): return RedirectResponse(url="/main") @app.get("/main", response_class=HTMLResponse) async def static_endpoint(request: Request): return templates.TemplateResponse("static/index.html", {"request": request}) import uvicorn if __name__ == '__main__': file = Path(__file__) uvicorn.run(app=f'{file.stem}:app', host="127.0.0.1", port=8000, reload=True) Vite App "Snipaste_2024-04-09_11-49-52.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/7f1c7152ad2a61dcc0085570e8a11668.png) "Snipaste_2024-04-09_12-22-53.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/e1d9479a18f469de0e867c989ffad93b.png)

0
1
0
浏览量118
楠楠不难难

fastapi 请求过多一般缓存方案是什么?

«fastapi 请求过多一般缓存方案是什么?» 本地开了 fastapi , 本身要处理的 post 请求过多,要对数据库写入 想到做请求缓存队列, 一般 fastapi 缓存方案是什么?

0
1
0
浏览量23
ciiiiinema

Python 的 FastAPI 框架有没有全局数据容器?

比如 "Flask" 里的 "g" 对象,比如存储一些用户身份信息以便其它方法去使用

0
1
0
浏览量26
无敌英俊大师兄

uvicorn 报错:Error loading ASGI app. Could not import module 'app'.?

上一个问题解决后出现的连锁问题: "https://segmentfault.com/q/1010000044426482" (https://segmentfault.com/q/1010000044426482) uvicorn 开启服务报错 "Error loading ASGI app. Could not import module "app"." 目录结构: my_app_name ├── py │ └── python.exe 等 ├── main.py ├── app.py └── run.bat run.bat @echo off REM 用 python.exe 调用 run.py 并传递所有输入参数 .\py\python.exe main.py %* main.py import sys import getopt import uvicorn import pathlib from multiprocessing import freeze_support if __name__ == "__main__": freeze_support() uvicorn.run('app:app', host="0.0.0.0", port=8000, reload=True, workers=1) app.py from fastapi import FastAPI app = FastAPI() @app.post("/xxx") # 以下略 运行run.bat 报错: "ERROR: Error loading ASGI app. Could not import module "app"." 我认为还是路径的问题,但我没有找到解决方案, 相似问题在 "https://stackoverflow.com/questions/60819376/fastapi-throws-an-error-error-loading-asgi-app-could-not-import-module-api" (https://link.segmentfault.com/?enc=G%2FiMWai5UIU4rn5ITOqWCQ%3D%3D.WMHqRgxearEZb0TQEucB2TQnMP5oAAZw01WarJ4SMSH9fpntxVanzvvLzQpoK%2B920hpEi%2FplrNsIHVn%2BKjMAQa%2BK7md1m3eC6sU8PIwzuuWg0OXulCwKkwulxvyujFpPGRfY%2B4Sez0%2B8Dp3Q8YSaN%2B3BqXnHqbBsxmfpro0im6M%3D) 但和我这不太一样 请问这该怎么办? 谢谢

0
1
0
浏览量36
Ufoooo4U

fastapi自带swagger文档如何嵌套展示?

swagger展示目标效果 * 后台管理 * 用户管理 * a接口 * b接口 * 文章管理 * c接口 * d接口 现在效果 * 后台管理 * a接口 * b接口 * c接口 * d接口 * 用户管理 * a接口 * b接口 * 文章管理 * c接口 * d接口 代码 routerAdmin = APIRouter( prefix='/admin', tags=['后台管理'] ) # routerUser文件a,b路由 routerAdmin.include_router(routerUser) # routerAdmin文件c,d路由 routerAdmin.include_router(routerArticle) app = FastAPI() app.include_router(routerAdmin) 问: 可以实现目标效果吗,如何实现.

0
1
0
浏览量20