Оба примера кода ниже вернутся
устранить ошибку 422 Unprocessable Entity
Server.py
Код: Выделить всё
from pydantic import BaseModel
from fastapi import UploadFile
class test(BaseModel):
id:str
question:str
@app.post('/request')
def request(item:test,input:UploadFile=Form(None)):
##do something
return
Код: Выделить всё
import request
json= {"id":"1234acv","question":"how are you"}
files = {
"input": (img, with open(file_path), mime_type)
}
response =request.post(endpoint,files=files,json=json)
_content:
b'{"detail":[{" type":"missing","loc":["body","item"],"msg":"Поле
обязательно","input":null}]}'
Я тоже попробовал следующий метод
Client.py(Случай 2)
Код: Выделить всё
import request
json= {"id":"1234acv","question":"how are you"}
files = {
"input": (img, with open(file_path), mime_type)
}
payload= {"item":json.dumps(json)}
response =request.post(endpoint,files=files,data=payload)
_content: b'{"detail":[{"type":"missing ","loc":["body","item"],"msg":"Поле
обязательно","input":null}]}' Сервер,py
< /blockquote>
Какой формат подходит для одновременной загрузки файла и JSON?
Подробнее здесь: https://stackoverflow.com/questions/791 ... -json-data
Мобильная версия