question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Colon in uri generate response 404

See original GitHub issue

Sanic can’t find the route if there’s a colon in the uri.

Code snippet

from sanic import Sanic, Request, HTTPResponse

app = Sanic('zzz')


@app.get(f'/abc/x:y')
async def main(_: Request):
    return HTTPResponse()


if __name__ == '__main__':
    app.run()

Expected behavior GET http://127.0.0.1:8000/abc/x:y 200 0

Actual behavior GET http://127.0.0.1:8000/abc/x:y 404 733

Environment

[2022-09-26 20:50:40 +0600] [13060] [INFO] Sanic v22.6.2
[2022-09-26 20:50:40 +0600] [13060] [INFO] Goin' Fast @ http://127.0.0.1:8000
[2022-09-26 20:50:40 +0600] [13060] [INFO] mode: production, single worker
[2022-09-26 20:50:40 +0600] [13060] [INFO] server: sanic, HTTP/1.1
[2022-09-26 20:50:40 +0600] [13060] [INFO] python: 3.10.5
[2022-09-26 20:50:40 +0600] [13060] [INFO] platform: Windows-10-10.0.19044-SP0
[2022-09-26 20:50:40 +0600] [13060] [INFO] packages: sanic-routing==22.3.0
[2022-09-26 20:50:40 +0600] [13060] [INFO] Starting worker [13060]

Additional context https://github.com/tiangolo/fastapi/issues/4892 https://github.com/encode/starlette/pull/1657

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ahopkinscommented, Dec 18, 2022

I am going to put this aside for now unless someone can make a compelling argument for why we need to handle this. It is the first time I have heard this come up and I am hesitant to add in support for this edge case when a viable alternative exists.

For anyone that needs:

from urllib.parse import quote

from sanic import Request, Sanic, json
from sanic.router import Router


class MyRouter(Router):
    def get(self, path, *args, **kwargs):
        return super().get(quote(path), *args, **kwargs)


app = Sanic("TestApp", router=MyRouter())


@app.route("/x:y")
async def handler(request: Request):
    return json({"foo": "bar"})

Or, perhaps a try/except is warranted:

    def get(self, path, *args, **kwargs):
        try:
            return super().get(path, *args, **kwargs)
        except NotFound:
            return super().get(quote(path), *args, **kwargs)
0reactions
Troniccommented, Dec 18, 2022

Closing as WONTFIX, given that it against specs and as @ahopkins noted a rare corner case with viable workarounds for those who need it anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When a url contains colon, it makes 404 response. After I ...
When a url contains colon, it makes 404 response. After I upgrade fastapi ... Colon in uri generate response 404 sanic-org/sanic-routing#67.
Read more >
Colons not being URL encoded in resource parameters
I've got around this issue by passing the URI as a query parameter instead of as part of the request URL. I did...
Read more >
URL with . and : does not work - Laracasts
Basically, it works with only dots, or only colons. If the URL contains a dot and colon, a 404 is thrown. Route: Route::get('/server/{ipport}', ......
Read more >
PQ77490: HAVING A SEMICOLON IN THE URL AND ... - IBM
Customer has coded multifail error404 error page, to send 404 type responses to the client. If the URI contains a semicolon then the...
Read more >
Using URL encoding to handle special characters in a ...
In this article, we will walk through a scenario where exceptions are thrown if such a URI with special character is not handled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found