【发布时间】:2021-01-25 03:36:56
【问题描述】:
我需要用多张图片点击 fastapi
@app.post("/text")
def get_text(files: List[UploadFile] = File(...)):
当我尝试使用 /docs 界面上传多张图片时它工作正常,我尝试使用一个文件它工作正常这里是它的代码
import requests
import json
def get_text(image_path):
#images={}
url = 'http://address/text'
try:
with open(image_path, "rb") as im:
image_data={"files":im}
response=requests.post(url,files=image_data)
return json.loads(response.text)
except Exception as er:
print("error occured")
return "{} error occured".format(er)
当我尝试向 image_data 添加更多图像但出现错误时。
image_data ={"files":[]}
for image in image_list:
with open(image, "rb") as im:
image_data['files'].append(im)
上面的代码试过了,没用。
上面运行后的错误信息 error message
【问题讨论】:
标签: python-3.x rest dictionary python-requests fastapi