2 months ago
I'm trying to make a super simple request from my rails app to my python (fast api) app using the internal network. I imported the fast api url on the variable FAST_API_URL with the value test-fast-api.railway.internal that is the internal url for the service. When I try to do the request on ruby to (@base_url = "http://#{ENV["FAST_API_URL"]}:8000") I see this error:
Error: Failed to connect to Fast API: Failed to open TCP connection to test-fast-api.railway.internal:8000 (Connection refused - connect(2) for "test-fast-api.railway.internal" port 8000)
I guess the problem could be the port, in case that's the error how can I know the right port? If not, how can I configure everything to make requests using the internal network?
4 Replies
2 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open sarahkb125 • about 2 months ago
2 months ago
Does this work?
Set PORT=8000 as a service variable in your FastAPI service
Update your Rails app to: @base_url = "http://#{ENV["FAST_API_URL"]}:8000"
Ensure your FastAPI app is listening on 0.0.0.0:$PORT
2 months ago
import uvicorn
if __name__ == "__main__":
uvicorn.run(
"app.main:app",
host="0.0.0.0",
port=8000,
reload=True,
)
This is how I start the server in python, so it always listen from the 8000 automatically so I guess it shouldn't be needed to define the port as a variable right?
faqndo97
import uvicorn if __name__ == "__main__": uvicorn.run( "app.main:app", host="0.0.0.0", port=8000, reload=True, )This is how I start the server in python, so it always listen from the 8000 automatically so I guess it shouldn't be needed to define the port as a variable right?
2 months ago
Just update it to this to support IPv6 connections:uvicorn.run(
"app.main:app",
host="::",
port=8000,
reload=True,
)
2 months ago
Thanks! That fixed the problem. So for internal connections the services should ensure to be able to support IPv6 connections.
Status changed to Solved chandrika • about 2 months ago