RedirectResponse to service hosted on a container timing out
See original GitHub issueFirst 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
@app.get("/container/somepath")
async def container():
return RedirectResponse("https://10.0.0.4:10401/somepath")
Description
I’m having an issue redirecting the request using the containers’ IP, the request it redirected but the response times out. I’m not sure if this can be fixed from my FastAPI project or from my server setup, but when testing with curl on the server, I get the right response data.
I am running a number of containers on a server, behind a reverse proxy which is running in another container. My FastAPI project is stored on the host, but the requests go through the reverse proxy container, where the FastAPI socket is mapped and consumed by nginx.
In the API, when I do a RedirectResponse using the host IP I get a response, but I would like to use the containers’ IP instead. The containers’ IP are not visible on the LAN (only from host or between them), but I can access them through port forwarding. If I manage to redirect using the internal IPs, I would remove port forwarding, and access these services through my FastAPI project,
The problem is that even though I can curl an endpoint from a container on the host or on the reverse proxy container using the internal IPs, the redirection is not working through FastAPI. Is there something I’m missing? Not sure what else I can do to debug this.
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.73.0
Python Version
3.9
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top GitHub Comments
That is good.
One note, you will want to use a async http client. Requests is sync so your process will stop at that call and not work on other things.
Appreciate that tip, thank you!