R
Railway5mo ago
Dem

socket.gaierror: [Errno -2] Name or service not known

I have a hypercorn app but am encountering this error: socket.gaierror: [Errno -2] Name or service not known. It works when I specify a railway.json that specifies a port, but only on a local host, not on the public domain. How can I fix this?
{
"deploy": {
"startCommand": "hypercorn main:app --bind \"0.0.0.0:8000\""
}
}
{
"deploy": {
"startCommand": "hypercorn main:app --bind \"0.0.0.0:8000\""
}
}
37 Replies
Percy
Percy5mo ago
Project ID: N/A
Brody
Brody5mo ago
you want to use
hypercorn main:app --bind [::]:$PORT
hypercorn main:app --bind [::]:$PORT
Dem
Dem5mo ago
Hmm same error:
sock.bind(binding)

socket.gaierror: [Errno -2] Name or service not known
sock.bind(binding)

socket.gaierror: [Errno -2] Name or service not known
Brody
Brody5mo ago
show me your new railway.json please
Dem
Dem5mo ago
{
"deploy": {
"startCommand": "hypercorn main:app --bind [::]:$PORT"
}
}
{
"deploy": {
"startCommand": "hypercorn main:app --bind [::]:$PORT"
}
}
Brody
Brody5mo ago
might need to escape some of it
hypercorn main:app --bind \"[::]:$PORT\"
hypercorn main:app --bind \"[::]:$PORT\"
Dem
Dem5mo ago
Same thing still
sock.bind(binding)

socket.gaierror: [Errno -2] Name or service not known
sock.bind(binding)

socket.gaierror: [Errno -2] Name or service not known
Brody
Brody5mo ago
hmm that's odd, is that not how it written here? https://github.com/vfehring/fastapi/blob/main/railway.json#L7 if it was wrong we absolutely would have heard of it by now
Dem
Dem5mo ago
I can try ading the schema and build fields?
Brody
Brody5mo ago
nah that's not the issue
Dem
Dem5mo ago
Should I ingore this error
No description
Brody
Brody5mo ago
share your repo? replace the railway.app domain with schema.up.railway.app and the error goes away
Dem
Dem5mo ago
Brody
Brody5mo ago
nope
Dem
Dem5mo ago
Let me try the new railway json Same thing
Dem
Dem5mo ago
This is what my repo looksl ike
No description
Brody
Brody5mo ago
delete the procfile that's a heroku thing mainly
Dem
Dem5mo ago
Ok
Brody
Brody5mo ago
also I'd like the build logs https://bookmarklets.up.railway.app/log-downloader/ before you push this change
Dem
Dem5mo ago
Oh I already pushed But it's the same error
Brody
Brody5mo ago
how can you be sure that railway is using the correct start command?
Dem
Dem5mo ago
Do you mean the hypercorn command?
Brody
Brody5mo ago
yes
Dem
Dem5mo ago
That works locally for me, maybe it's not the correct command for railway though
Brody
Brody5mo ago
I mean, it works here for fastapi
Dem
Dem5mo ago
When I hard code the port to 8000, it works on railway except I can't access the API on public domain Ya I'm using fastapi Yup
Brody
Brody5mo ago
send your dockerfile?
Dem
Dem5mo ago
FROM python:3.9

WORKDIR /app

COPY . /app

RUN pip install --trusted-host pypi.python.org -r requirements.txt

RUN apt-get update

RUN apt-get install -y wget unzip

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

RUN apt install -y ./google-chrome-stable_current_amd64.deb

RUN rm google-chrome-stable_current_amd64.deb

RUN apt-get clean
FROM python:3.9

WORKDIR /app

COPY . /app

RUN pip install --trusted-host pypi.python.org -r requirements.txt

RUN apt-get update

RUN apt-get install -y wget unzip

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

RUN apt install -y ./google-chrome-stable_current_amd64.deb

RUN rm google-chrome-stable_current_amd64.deb

RUN apt-get clean
Dem
Dem5mo ago
This is what I get when I hard code to 8000, it runs the code but not accessible on public domain
No description
Brody
Brody5mo ago
may I ask what you are using chrome for?
Dem
Dem5mo ago
it's for simulating user visits to our site was debugging something sorry
Brody
Brody5mo ago
it not the ideal solution, hard code the port to 8000 and then set a PORT service variable to 8000
Dem
Dem5mo ago
Got it, thanks!
Brody
Brody5mo ago
let me know if that works
Dem
Dem5mo ago
That worked! Thank you
Brody
Brody5mo ago
no problem!