• <small id='yWRcC'></small><noframes id='yWRcC'>

  • <i id='yWRcC'><tr id='yWRcC'><dt id='yWRcC'><q id='yWRcC'><span id='yWRcC'><b id='yWRcC'><form id='yWRcC'><ins id='yWRcC'></ins><ul id='yWRcC'></ul><sub id='yWRcC'></sub></form><legend id='yWRcC'></legend><bdo id='yWRcC'><pre id='yWRcC'><center id='yWRcC'></center></pre></bdo></b><th id='yWRcC'></th></span></q></dt></tr></i><div id='yWRcC'><tfoot id='yWRcC'></tfoot><dl id='yWRcC'><fieldset id='yWRcC'></fieldset></dl></div>
      <bdo id='yWRcC'></bdo><ul id='yWRcC'></ul>
    <legend id='yWRcC'><style id='yWRcC'><dir id='yWRcC'><q id='yWRcC'></q></dir></style></legend>

      1. <tfoot id='yWRcC'></tfoot>
      2. 如何在FastAPI POST请求中同时添加文件和JSON正文?

        How to add both file and JSON body in a FastAPI POST request?(如何在FastAPI POST请求中同时添加文件和JSON正文?)
      3. <small id='Y0hYG'></small><noframes id='Y0hYG'>

          <bdo id='Y0hYG'></bdo><ul id='Y0hYG'></ul>

          1. <i id='Y0hYG'><tr id='Y0hYG'><dt id='Y0hYG'><q id='Y0hYG'><span id='Y0hYG'><b id='Y0hYG'><form id='Y0hYG'><ins id='Y0hYG'></ins><ul id='Y0hYG'></ul><sub id='Y0hYG'></sub></form><legend id='Y0hYG'></legend><bdo id='Y0hYG'><pre id='Y0hYG'><center id='Y0hYG'></center></pre></bdo></b><th id='Y0hYG'></th></span></q></dt></tr></i><div id='Y0hYG'><tfoot id='Y0hYG'></tfoot><dl id='Y0hYG'><fieldset id='Y0hYG'></fieldset></dl></div>
              <tbody id='Y0hYG'></tbody>

              <legend id='Y0hYG'><style id='Y0hYG'><dir id='Y0hYG'><q id='Y0hYG'></q></dir></style></legend>
              <tfoot id='Y0hYG'></tfoot>

                  本文介绍了如何在FastAPI POST请求中同时添加文件和JSON正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  具体地说,我希望下面的示例能够工作:

                  from typing import List
                  from pydantic import BaseModel
                  from fastapi import FastAPI, UploadFile, File
                  
                  
                  app = FastAPI()
                  
                  
                  class DataConfiguration(BaseModel):
                      textColumnNames: List[str]
                      idColumn: str
                  
                  
                  @app.post("/data")
                  async def data(dataConfiguration: DataConfiguration,
                                 csvFile: UploadFile = File(...)):
                      pass
                      # read requested id and text columns from csvFile
                  

                  如果这不是POST请求的正确方式,请告诉我如何从FastAPI中上载的CSV文件中选择所需的列。

                  推荐答案

                  不能将表单数据与JSON混用。

                  每个FastAPIdocumentation:

                  警告: 您可以在路径操作中声明多个FileForm参数,但是您不能同时声明期望作为JSON接收的Body字段,因为请求将使用multipart/form-data而不是application/json对正文进行编码。 这不是FastAPI的限制,它是HTTP协议的一部分。

                  但是,您可以使用Form(...)作为临时解决办法,将额外字符串附加为form-data

                  from typing import List
                  from fastapi import FastAPI, UploadFile, File, Form
                  
                  
                  app = FastAPI()
                  
                  
                  @app.post("/data")
                  async def data(textColumnNames: List[str] = Form(...),
                                 idColumn: str = Form(...),
                                 csvFile: UploadFile = File(...)):
                      pass
                  

                  这篇关于如何在FastAPI POST请求中同时添加文件和JSON正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                    <legend id='U5qVy'><style id='U5qVy'><dir id='U5qVy'><q id='U5qVy'></q></dir></style></legend>
                      <tbody id='U5qVy'></tbody>
                      <bdo id='U5qVy'></bdo><ul id='U5qVy'></ul>
                        <tfoot id='U5qVy'></tfoot>

                        <small id='U5qVy'></small><noframes id='U5qVy'>

                          • <i id='U5qVy'><tr id='U5qVy'><dt id='U5qVy'><q id='U5qVy'><span id='U5qVy'><b id='U5qVy'><form id='U5qVy'><ins id='U5qVy'></ins><ul id='U5qVy'></ul><sub id='U5qVy'></sub></form><legend id='U5qVy'></legend><bdo id='U5qVy'><pre id='U5qVy'><center id='U5qVy'></center></pre></bdo></b><th id='U5qVy'></th></span></q></dt></tr></i><div id='U5qVy'><tfoot id='U5qVy'></tfoot><dl id='U5qVy'><fieldset id='U5qVy'></fieldset></dl></div>