fastapi
fastapi copied to clipboard
Dash at end of a router URL Problem
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the FastAPI documentation, with the integrated search.
- [X] I already searched in Google "How to X in FastAPI" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to FastAPI but to Pydantic.
- [X] I already checked if it is not related to FastAPI but to Swagger UI.
- [X] I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
router = APIRouter(
prefix="/care_line_people",
tags=["CareLinePeople"],
responses={404: {"description": "Not found"}},
)
@router.get('/add_identification_to_person')
def add_identification_to_person():
return '2'
@router.get('/add_identification_to_person_teste/')
def add_identification_to_person():
return '3'
Description
If I call bot endpoints locally it behaves as expected. Only method GET to the exact correct path, returns me what I want. Call GET with '/add_identification_to_person', returns 2 and call '/add_identification_to_person_teste/' (with dash incluse) returns 3. If I call GET with '/add_identification_to_person/' it returns me 2 and if I call POST with '/add_identification_to_person' it returns {details: method not allowed}.
The problema appears when I run this aplication on a EC2 in AWS configured with an Elastic Beanstalk (with Docker) and a Load Balancer where if I call any HTTP METHOD in a path ending with a '/' it returns me that function normaly. So, if I call POST '/add_identification_to_person_teste' it returns 3 and if a call '/add_identification_to_person/' it returns 2.
I could found an explanation for this problem.
Operating System
Linux
Operating System Details
Both machines, mine and AWS are linux x86.
FastAPI Version
fastapi==0.79.0
Python Version
3.8
Additional Context
No response
That is extremely weird behaviour. Could you adjust your endpoints like so:
from fastapi import Request
@router.get('/add_identification_to_person')
def add_identification_to_person(r: Request):
return r.__dict__
and see what the return value is? This will include all elements of the Scope
of the request, and thus also the method.
You say that POST
works while you have no routes that support POST METHOD?
@JarroVGIT: When I added the Request it breaks my endpoint with this error: - RecursionError: maximum recursion depth exceeded while calling a Python object
@iudeen: Yes, but only on an AWS server and with a forward slash ("/") ending the URL. So if a put a forward slash at the URL ending it accepts all HTTP METHODS.
FYI that is a "forward slash" not a dash "-"
@four43 sorry I wrote it fast and I didnt write it properly. It is a foward slash indeed