小编hoa*_*ham的帖子

FastAPI中上传多张图片的请求格式

例子

这是我尝试上传图像列表的代码:

import requests
import glob
import cv2

path = glob.glob("test_folder/*", recursive=True) # a list of image's path

lst_img = []
for p in path[:3]:
    # img = cv2.imread(p)
    lst_img.append((p, open(p, 'rb'), "image/jpeg"))

data = {"files": lst_img}

url = "http://localhost:6789/" # url api of app

res = requests.post(url=url, data=data)

print(res.status_code)

print(res.text)

Run Code Online (Sandbox Code Playgroud)

描述

我正在尝试通过 Python 请求(包)将图像列表上传到 FastAPI 端点,但也许我的请求格式错误,导致错误422

import requests
import glob
import cv2

path = glob.glob("test_folder/*", recursive=True) # a list of image's path

lst_img = []
for p …
Run Code Online (Sandbox Code Playgroud)

python file-upload python-requests fastapi

4
推荐指数
1
解决办法
4448
查看次数

标签 统计

fastapi ×1

file-upload ×1

python ×1

python-requests ×1