Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

When a url contains colon, it makes 404 response. After I upgrade fastapi from 0.75.0 to 0.77.1. #4892

Closed
9 tasks done
kevinGan opened this issue May 12, 2022 · 10 comments · Fixed by encode/starlette#1675
Closed
9 tasks done
Labels
question Question or problem question-migrate

Comments

@kevinGan
Copy link

kevinGan commented May 12, 2022

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

main.py

....
@app.post("/files:upload_homework")
async def create_file():
    ......

--------------------    
$ curl -X POST "http://127.0.0.1:8000/files:upload_homework"
{"detail":"Not Found"}%

------------
I run my fastapi App below command:

uvicorn main:app --host 0.0.0.0 --port 80

Description

It works in below packages:

$ pip freeze
anyio==3.5.0
asgiref==3.5.0
click==8.0.4
fastapi==0.75.0
h11==0.13.0
httptools==0.4.0
idna==3.3
Jinja2==3.0.3
MarkupSafe==2.1.1
pydantic==1.9.0
python-dotenv==0.19.2
python-multipart==0.0.5
pytz==2022.1
PyYAML==6.0
six==1.16.0
sniffio==1.2.0
starlette==0.17.1
typing-extensions==4.1.1
uvicorn==0.17.6
uvloop==0.16.0
watchgod==0.8.1
websockets==10.2

It can not works below packages:

$ pip freeze                                                
anyio==3.5.0
asgiref==3.5.0
click==8.0.4
fastapi==0.77.1
h11==0.13.0
httptools==0.4.0
idna==3.3
Jinja2==3.0.3
MarkupSafe==2.1.1
pydantic==1.9.0
python-dotenv==0.19.2
python-multipart==0.0.5
pytz==2022.1
PyYAML==6.0
six==1.16.0
sniffio==1.2.0
starlette==0.19.1
typing-extensions==4.1.1
uvicorn==0.17.6
uvloop==0.16.0
watchgod==0.8.1
websockets==10.2

Operating System

Linux, macOS

Operating System Details

No response

FastAPI Version

0.77.1

Python Version

Python 3.9.12

Additional Context

No response

@kevinGan kevinGan added the question Question or problem label May 12, 2022
@xingdongzhe
Copy link

xingdongzhe commented May 14, 2022

This is not FastAPI issue, that is starlette issue.
You can run below code to see the differences

from starlette.routing import compile_path
from starlette import __version__
print(__version__)

print(compile_path("/files:upload_homework"))

Here is my result

0.17.1
(re.compile('^/files:upload_homework$'), '/files:upload_homework', {})

0.19.1
(re.compile('^/files$'), '/files:upload_homework', {})

So you can see that starlette use different reget to math url path
let's why is for this
Here is the code
And we got from commit message that is for Remove port from Host routing regex https://github.com/encode/starlette/pull/1322

# 0.19.1
path_regex += re.escape(path[idx:].split(":")[0]) + "$"

# 0.17.1
path_regex += re.escape(path[idx:]) + "$"

So you should not use : on url path or you make one issue to starlette for this

@kevinGan
Copy link
Author

Thank you for reply.

We use google API design standard in my team. (https://cloud.google.com/apis/design/custom_methods?hl=zh-cn)

Maybe I should make an issue to starlette for this.

@bodograumann
Copy link

bodograumann commented May 31, 2022

We have the same problem. As a workaround you can append {dummy:path} at the end of your route, @kevinGan .
Oh and thanks so much for your research @xingdongzhe, it helped me immensely.

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Jun 7, 2022

Starlette 0.20.2 contains a fix for this. We've just released that version. :)

@bodograumann
Copy link

Needs #4820 and #4936 and bump to 0.20.2 afterwards.

@mhadam
Copy link

mhadam commented Jul 1, 2022

Wouldn't it be worth having a warning or something in documentation? This is a pretty major regression.

@bodograumann
Copy link

It is already fixed in starlette. The dependency "just" needs to be updated in fastapi now.

@bodograumann
Copy link

bodograumann commented Sep 16, 2022

This issue is fixed in fastapi 0.85.0.

@tiangolo
Copy link
Owner

Thanks for the help here everyone! 👏 🙇

If that solves the original problem, then you can close this issue @kevinGan ✔️

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2022

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

@github-actions github-actions bot closed this as completed Dec 1, 2022
@tiangolo tiangolo reopened this Feb 27, 2023
@github-actions github-actions bot removed the answered label Feb 27, 2023
Repository owner locked and limited conversation to collaborators Feb 27, 2023
@tiangolo tiangolo converted this issue into discussion #6398 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Question or problem question-migrate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants