Route request doesn't help

Hi!
I’m trying to setup a small server with Sanic, like so

from helpers.helper import create_app, run_app
from controllers import usercontroller
from sanic import response


sanic_app = create_app(
    blueprints=((usercontroller.bp,))
)


@sanic_app.route("/")
async def home(request):
   return response.text("Hello Sanic")


if __name__ == "__main__":  # pragma: no cover
    run_app(sanic_app,debug=True)

And this is the part which actually contains the initizalization

from sanic import Sanic, Blueprint
from sanic.exceptions import SanicException
from typing import Iterable, Any, Optional, Dict
from http import HTTPStatus
import json
from sanic.request import Request
from sanic.response import HTTPResponse
from .exceptions import ApiException
from decouple import config
import logging
from pymongo import MongoClient
import psycopg2

LOGGER = logging.getLogger(__name__)


def create_app(blueprints: Iterable[Blueprint] = None) -> Sanic:
    """
    Creates the Sanic application.
    :param blueprints: the Sanic blueprints to register.
    :return: the created Sanic application.
    """

    app = Sanic(__name__)


    @app.middleware("request")
    async def before_request(request: Request) -> None:
        """
        Performs certain logics before executing the actual request that came from the client
        :param request: the received request from the client
        """
        #TODO Insert any logic to perform before proceeding to actual REQ
        pass

    @app.listener('before_server_start')
    async def start_dbs(app, loop):
        app.pgsql = psycopg2.connect(host=config("HOST", cast=str),
                                     database=config("DB_NAME", cast=str),
                                     user=config("USER_DB", cast=str),
                                     password=config("USER_DB_PASS", cast=str))
        app.mongo = MongoClient(config("MONGO_CONNECTION_URL", cast=str))
        print("ciao")

    @app.listener('before_server_stop')
    async def stop_dbs(app, loop):
        app.pgsql.close()
        app.mongo.disconnect()

    @app.exception(ApiException)
    async def handle_exception(request: Request, exception: ApiException) -> HTTPResponse:
        LOGGER.exception(exception)
        return json_response(
            body={"error_code": exception.error_code, "message": exception.error_message},
            status=exception.status_code,
        )

    @app.exception(SanicException)
    async def handle_unknown_exception(request: Request, exception: SanicException) -> HTTPResponse:
        LOGGER.exception(exception)
        return json_response(
            body={"error_code": ApiException.error_code, "message": ApiException.error_message},
            status=HTTPStatus(exception.status_code),
        )

    @app.exception(Exception)
    async def handle_bare_exception(request: Request, exception: Exception) -> HTTPResponse:
        LOGGER.exception(exception)
        return json_response(
            body={"error_code": ApiException.error_code, "message": ApiException.error_message},
            status=ApiException.status_code,
        )

    if blueprints is not None:
        for blueprint in blueprints:
            app.blueprint(blueprint)

    return app

def json_response(
    body: Any,
    status: HTTPStatus = HTTPStatus.OK,
    headers: Optional[Dict] = None,
    content_type: str = "application/json; charset=utf-8",
) -> HTTPResponse:
    """
    Creates a JSON to return to the caller with the given arguments.
    :param body: the response body.
    :param status: the response HTTP status.
    :param headers: the response HTTP headers.
    :param content_type: the response content type.
    :return: the resulting HTTPResponse object.
    """
    return HTTPResponse(
        body="" if body is None else json.dumps(body, cls=json.JSONEncoder),
        status=status.value,
        headers=headers,
        content_type=content_type,
    )

def run_app(sanic_app: Sanic, debug: bool= False) -> None:
    """
    Utility function to run the sanic application during development.
    :param sanic_app: the Sanic application to run.
    :param debug: whether the application should go on debug or not. Default: False
    """
    sanic_app.run(
        host=config("HOST", cast=str),
        port=config("PORT", cast=str),
        debug=debug
    )

Then, I also attach the following BluePrint

from sanic import Blueprint
from sanic.request import Request
from sanic.response import HTTPResponse
from decouple import config

bp = Blueprint("user", url_prefix="user")


@bp.route("/prova", version=1 ,methods=["GET"])
async def register(request: Request) -> HTTPResponse:
    """
    Register the user in the system
    :param request: the request sent from the user. Will contain the necessary parameters to save the user in the system
    :return 200 if the user is registered, 500 if an error happens
    """
    print("ciao")

@bp.route("/add", version=1,methods=["POST"])
async def register(request: Request) -> HTTPResponse:
    """
    Register the user in the system
    :param request: the request sent from the user. Will contain the necessary parameters to save the user in the system
    :return 200 if the user is registered, 500 if an error happens
    """

But if I try to go to http://localhost:8071/user/prova, Sanic returns me in the logs a 404, while in the browser it shows a 500 status. What am I doing wrong?

I think when you see the issue yourself, it will become real simple and obvious to you.

Add this to your run_app

print(sanic_app.router.routes_all.keys())

In your endpoint handlers, you are defining version=1. That has the impact of adding /v1 to your routes’ paths.

Too much obvious that I’m even sorry for having opened a post :frowning:
Thank you for the help!

I think we have all been there.