小编Alu*_*uko的帖子

使用 FastAPI,如何在 OpenAPI (Swagger) 文档上的请求标头上将字符集添加到内容类型(媒体类型)?

使用 FastAPI,如何在 OpenAPI (Swagger) 文档上的请求标头上将字符集添加到内容类型(媒体类型)?

@app.post("/")
def post_hello(username: str = Form(...)):
   return {"Hello": username}
Run Code Online (Sandbox Code Playgroud)

OpenAPI (http:///docs) 显示“ application/x-www-form-urlencoded ”。

openapi文档

我尝试改变如下:

def post_hello(username: str = Form(..., media_type="application/x-www-form-urlencoded; charset=cp932")):
   return {"Hello": "World!", "userName": username}
Run Code Online (Sandbox Code Playgroud)

但不能添加charset=cp932

我想根据请求将“ application/x-www-form-urlencoded; charset=cp932 ”设置为 Content-Type 。我想获得由字符集解码的用户名。

python-3.x swagger openapi fastapi

3
推荐指数
1
解决办法
6787
查看次数

标签 统计

fastapi ×1

openapi ×1

python-3.x ×1

swagger ×1