Python 3.x 使用路径参数的FastAPI通用API请求

Python 3.x 使用路径参数的FastAPI通用API请求,python-3.x,api,fastapi,Python 3.x,Api,Fastapi,如何使用FastAPI的path参数发出通用API请求? 在下面的代码中,我希望数据\源\名称作为字典配置的键传递。 正在使用特定值的类型声明对象“item”,该值的键是“config”字典中的“data\u source\u name”。 但在将“数据源名称”作为字典中的键传递时,它显示“definedPylancereportUndefinedVariable” 代码 @datasource.post("/{data_source_name}/test_connection&quo

如何使用FastAPI的path参数发出通用API请求? 在下面的代码中,我希望数据\源\名称作为字典配置的键传递。 正在使用特定值的类型声明对象“item”,该值的键是“config”字典中的“data\u source\u name”。 但在将“数据源名称”作为字典中的键传递时,它显示“definedPylancereportUndefinedVariable”

代码

@datasource.post("/{data_source_name}/test_connection")
async def test_connections(data_source_name, item: ct.config[data_source_name]):
图片

@datasource.post("/{data_source_name}/test_connection")
async def test_connections(data_source_name, item: ct.config[data_source_name]):

我相信你不能那样做。但是,您可以为Config创建一个接口类,这样OpenAPI仍然可以处理它。