[Python] How to pass URL as a path parameter to a FastAPI route?

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    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}


    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

    Continue reading...

Compartilhe esta Página