Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL path with colon (":") results in 404 not found #1674

Closed
dwinston opened this issue Jun 3, 2022 Discussed in #1673 · 3 comments
Closed

URL path with colon (":") results in 404 not found #1674

dwinston opened this issue Jun 3, 2022 Discussed in #1673 · 3 comments

Comments

@dwinston
Copy link

dwinston commented Jun 3, 2022

Discussed in #1673

Originally posted by dwinston June 3, 2022
I find that I can't GET or POST to a path containing a colon (":"). An example in FastAPI (which uses Starlette):

from fastapi import FastAPI

app = FastAPI()

@app.get("/items:queue")
def queue_new_item():
    return "An item has been queued for later inclusion."

On uvicorn main:app --reload (FYI Python 3.9.12 and FastAPI 0.78.0 on MacOS), I get a 404 response from GET http://127.0.0.1:8000/items:queue.

I also filed this issue in the fastapi repo (tiangolo/fastapi#4984), but I suspect that Starlette's use of colons for path parameter converters (https://www.starlette.io/routing/) may be playing a role here.

Is this a bug? I am trying to follow the official google cloud APIs "custom methods" pattern https://cloud.google.com/apis/design/custom_methods:

For custom methods, they should use the following generic HTTP mapping:
https://service.name/v1/some/resource/name:customVerb

@dwinston
Copy link
Author

dwinston commented Jun 3, 2022

from starlette.routing import compile_path

compile_path("/queries:run")

outputs

(re.compile(r'^/queries$', re.UNICODE), '/queries:run', {})

This seems wrong!

@dwinston
Copy link
Author

dwinston commented Jun 4, 2022

I suspect 7c7ec5a broke this. It works in starlette 0.17.1 (I have a deployment using this version; I was wondering why colon-including routes are not working for me locally, where I am using 0.19.1 -- via latest FastAPI: https://fastapi.tiangolo.com/release-notes/), and I see that this commit was included since 0.18.0.

/cc @WhiteApfel @aminalaee @Kludex

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 5, 2022

The fix will be available on Starlette 0.20.2.

@Kludex Kludex closed this as completed Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants