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

20 messages · Page 1 of 1 (latest)

pastel berry
#

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
}

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?

real fernBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

covert cloakBOT
#

Project ID: 7d9659a4-cd22-47d5-b1f7-ed6ce4247406

bitter shell
#

what port is the python app listening on?

pastel berry
bitter shell
#

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

pastel berry
#

should I set something like this:
web: uvicorn main:app --host='::' --port=${PORT:-5000}
in my Procfile?

#

currently I'm using this:
web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}

bitter shell
#

im not completely sure thats valid, but worth a shot

pastel berry
# bitter shell im not completely sure thats valid, but worth a shot

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)

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"

bitter shell
#

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

pastel berry
#

I thought :: would make it accessible no matter the port, my bad

#

will try again!

bitter shell
#

thats just any interface, not any port

pastel berry
#

it's working now, with :: and a fixed port, thx a lot!

#

:)

bitter shell
#

no problem!