相关疑难解决方法(0)

How to pass URL as a path parameter to a FastAPI route?

I have created a simple API using FastAPI, and I am trying to pass a URL to a FastAPI route as an arbitrary path parameter.

from fastapi import FastAPI
app = FastAPI()
@app.post("/{path}")
def pred_image(path:str):
    print("path",path)
    return {'path':path}
Run Code Online (Sandbox Code Playgroud)

When I test it, it doesn't work and throws an error. I am testing it this way:

http://127.0.0.1:8000/https://raw.githubusercontent.com/ultralytics/yolov5/master/data/images/zidane.jpg
Run Code Online (Sandbox Code Playgroud)

python starlette fastapi

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

标签 统计

fastapi ×1

python ×1

starlette ×1