所以我正在学习 FastAPI,并试图弄清楚如何正确返回状态代码。我创建了一个用于上传文件的端点,并且我想在文件格式不受支持的情况下做出特殊响应。似乎我按照官方文档做了一切,但我总是收到422 Unprocessable Entity错误。
这是我的代码:
from fastapi import FastAPI, File, UploadFile, status
from fastapi.openapi.models import Response
app = FastAPI()
@app.post('/upload_file/', status_code=status.HTTP_200_OK)
async def upload_file(response: Response, file: UploadFile = File(...)):
"""End point for uploading a file"""
if file.content_type != "application/pdf":
response.status_code = status.HTTP_415_UNSUPPORTED_MEDIA_TYPE
return {f'File {file.filename} has unsupported extension type'}
return {'filename': file.content_type}
Run Code Online (Sandbox Code Playgroud)
先感谢您!
所以我正在尝试学习打字模块,但我完全陷入bound=困境。我已经读过这个综合主题好几次了,但由于我是新手,所以我不太了解。
您能解释一下bound=上限是什么意思吗?(最好是一个简单的例子)
预先谢谢您!
所以我的表有很多列。我正在尝试从该表所在的另一个数据库进行 pxf 连接。有什么方法可以复制或导出所有列名-数据类型对,这样我就不必在创建外部表时一一宣布它?