小编mvi*_*rra的帖子

FastAPI POST - 错误 422 详细信息'': ( ( loc'':(body file msg'':field required'', type'': value_error Missing)))

我想在后端读取这个 xlsx 文件。当我使用 swagger 时,我得到了它,但是当我在前端测试时,我收到错误 422 - devtools/网络详细信息'': ( ( loc'':(body file msg'':field required'', type'': value_error 丢失)))。

router = APIRouter()

@router.post('/')
async def upload_file(file: Uploadfile = File(...)):

  try:
    arquivo = await file.read()
    df_cambio = pd.read_excel(arquivo)
    cambio_dict = df_cambio.to_dict('index')
    
    print(cambio_dict)
    return{"file_name": file.filename}
  
  except Exception as e:
    exception_handler(e)
Run Code Online (Sandbox Code Playgroud)

反应->

export defaut function Dropzone() {
const [create, {isLoading}] = usePost();

const handleSubmit = (res) => {
    create('cambios', { data:res.file }})
};
if (isLoading) { return <LoadingPageSkeleton />;}

return (

<BasicForm
  initialValues={{}}
  onSubmit={handleSubmit}
> …
Run Code Online (Sandbox Code Playgroud)

python forms post typescript fastapi

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

fastapi ×1

forms ×1

post ×1

python ×1

typescript ×1