R
Railway17mo ago
_mati

Having issue connecting to a Python (uvicorn) internal app through Golang app

So, I have a Python app that runs a uvicorn + FastAPI server. I don't want to expose it to a public network, I only need to use it internally. It's working fine. I also have a Go app that consumes info from this Python server. When I try to ping the server with this code:
func PingPythonServer(url string) error {
client := http.Client{
Timeout: 5 * time.Second,
}

url = "http://" + url
res, err := client.Get(fmt.Sprintf("%s/ping/", url))
if err != nil {
return err
}

if res.StatusCode != http.StatusOK {
return errors.New("GPT server is not ready")
}

return nil
}
func PingPythonServer(url string) error {
client := http.Client{
Timeout: 5 * time.Second,
}

url = "http://" + url
res, err := client.Get(fmt.Sprintf("%s/ping/", url))
if err != nil {
return err
}

if res.StatusCode != http.StatusOK {
return errors.New("GPT server is not ready")
}

return nil
}
url param is the Private Networking URL you automatically assigned. I tried adding "http://" prefix, removing it, adding :80 port, etc but it's not working unfortunately. I'm getting this error message: Get \"http://gostock-python-sv.railway.internal/ping/\": dial tcp [fd12:1e3f:72a3::2c:a44e:2e7]:80: connect: connection refused The server is working fine. If I expose it to the public network, I can access to it. If I remove the HTTP scheme, I get this error: Get \"gostock-python-sv.railway.internal/ping/\": unsupported protocol scheme \"\" Project ID: 7d9659a4-cd22-47d5-b1f7-ed6ce4247406 Any help on this, please?
Solution:
should I set something like this: web: uvicorn main:app --host='::' --port=${PORT:-5000} in my Procfile?...
Jump to solution
13 Replies
Percy
Percy17mo ago
Project ID: 7d9659a4-cd22-47d5-b1f7-ed6ce4247406
Brody
Brody17mo ago
what port is the python app listening on?
_mati
_matiOP17mo ago
initially it was on 5000, then I tried with 80, still the same problem
Brody
Brody17mo ago
keep it on a non privileged port for good measure is uvicorn listening on :: aka all hosts both ipv6 and ipv4, since the internal network is ipv6 only
Solution
_mati
_mati17mo ago
should I set something like this: web: uvicorn main:app --host='::' --port=${PORT:-5000} in my Procfile?
_mati
_matiOP17mo ago
currently I'm using this: web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}
Brody
Brody17mo ago
im not completely sure thats valid, but worth a shot
_mati
_matiOP17mo ago
tried using above command with ::, I got these logs:
INFO: Started server process [1]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://[::]:7862 (Press CTRL+C to quit)
INFO: Started server process [1]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://[::]:7862 (Press CTRL+C to quit)
still getting this error when pinging the server: "Get \"http://gostock-python-sv.railway.internal/ping/\": dial tcp [fd12:1e3f:72a3::1a:fd7c:7c42]:80: connect: connection refused"
Brody
Brody17mo ago
uvicorn is running on port 7862 but you are trying to make a request with port 80 in the python's service variables set PORT to 8080, or some other 4 digit number, then make requests with that port
_mati
_matiOP17mo ago
I thought :: would make it accessible no matter the port, my bad will try again!
Brody
Brody17mo ago
thats just any interface, not any port
_mati
_matiOP17mo ago
it's working now, with :: and a fixed port, thx a lot! :)
Brody
Brody17mo ago
no problem!
Want results from more Discord servers?
Add your server