Flask API crashing shortly after deploy (waitress)

Traceback (most recent call last):

File "/venv/lib/python3.12/site-packages/waitress/adjustments.py", line 374, in __init__

for s in socket.getaddrinfo(

^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/socket.py", line 963, in getaddrinfo

for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

socket.gaierror: [Errno -8] Servname not supported for ai_socktype

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/venv/bin/waitress-serve", line 8, in <module>

sys.exit(run())

^^^^^

File "/venv/lib/python3.12/site-packages/waitress/runner.py", line 298, in run

_serve(app, **kw)

File "/venv/lib/python3.12/site-packages/waitress/__init__.py", line 13, in serve

server = _server(app, **kw)

^^^^^^^^^^^^^^^^^^

File "/venv/lib/python3.12/site-packages/waitress/server.py", line 49, in create_server

adj = Adjustments(**kw)

^^^^^^^^^^^^^^^^^

File "/venv/lib/python3.12/site-packages/waitress/adjustments.py", line 401, in __init__

raise ValueError("Invalid host/port specified.")

ValueError: Invalid host/port specified.
Traceback (most recent call last):

File "/venv/lib/python3.12/site-packages/waitress/adjustments.py", line 374, in __init__

for s in socket.getaddrinfo(

^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/socket.py", line 963, in getaddrinfo

for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

socket.gaierror: [Errno -8] Servname not supported for ai_socktype

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/venv/bin/waitress-serve", line 8, in <module>

sys.exit(run())

^^^^^

File "/venv/lib/python3.12/site-packages/waitress/runner.py", line 298, in run

_serve(app, **kw)

File "/venv/lib/python3.12/site-packages/waitress/__init__.py", line 13, in serve

server = _server(app, **kw)

^^^^^^^^^^^^^^^^^^

File "/venv/lib/python3.12/site-packages/waitress/server.py", line 49, in create_server

adj = Adjustments(**kw)

^^^^^^^^^^^^^^^^^

File "/venv/lib/python3.12/site-packages/waitress/adjustments.py", line 401, in __init__

raise ValueError("Invalid host/port specified.")

ValueError: Invalid host/port specified.
Solution:
try this instead
CMD /venv/bin/waitress-serve --port=$PORT --call weasyprint_rest:app
CMD /venv/bin/waitress-serve --port=$PORT --call weasyprint_rest:app
I'm just guessing though...
Jump to solution
12 Replies
Percy
Percy10mo ago
Project ID: 6ec4e69f-153c-42b1-8399-d4fbd6db04fb
meaniebeanie22
meaniebeanie22OP10mo ago
6ec4e69f-153c-42b1-8399-d4fbd6db04fb
Brody
Brody10mo ago
what's your start command?
meaniebeanie22
meaniebeanie22OP10mo ago
WORKDIR /app ENTRYPOINT ["/venv/bin/waitress-serve", "--listen=*:$PORT" ,"weasyprint_rest:app"] i have no PORT env variable in the service vars and im not sure what to set it to/how to let railway set it
Brody
Brody10mo ago
can you send the full dockerfile?
meaniebeanie22
meaniebeanie22OP10mo ago
FROM python:slim-bullseye AS builder
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev gtk+3.0 && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip

FROM builder AS builder-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt

FROM builder-venv AS tester
COPY . /app
WORKDIR /app
RUN /venv/bin/pytest

FROM python:slim-bullseye AS runner
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes gtk+3.0 curl jq

COPY --from=tester /venv /venv
COPY --from=tester /app/weasyprint_rest /app/weasyprint_rest
ENV PRODUCTION "true"
ENV FLASK_ENV=production

WORKDIR /app
ENTRYPOINT ["/venv/bin/waitress-serve", "--listen=*:$PORT" ,"weasyprint_rest:app"]

HEALTHCHECK --start-period=5s --interval=10s --timeout=10s --retries=5 \
CMD curl --silent --fail --request GET http://localhost:5000/api/v1.0/health \
| jq --exit-status '.status == "OK"' || exit 1

USER 1001
LABEL name={NAME}
LABEL version={VERSION}
FROM python:slim-bullseye AS builder
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev gtk+3.0 && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip

FROM builder AS builder-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt

FROM builder-venv AS tester
COPY . /app
WORKDIR /app
RUN /venv/bin/pytest

FROM python:slim-bullseye AS runner
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes gtk+3.0 curl jq

COPY --from=tester /venv /venv
COPY --from=tester /app/weasyprint_rest /app/weasyprint_rest
ENV PRODUCTION "true"
ENV FLASK_ENV=production

WORKDIR /app
ENTRYPOINT ["/venv/bin/waitress-serve", "--listen=*:$PORT" ,"weasyprint_rest:app"]

HEALTHCHECK --start-period=5s --interval=10s --timeout=10s --retries=5 \
CMD curl --silent --fail --request GET http://localhost:5000/api/v1.0/health \
| jq --exit-status '.status == "OK"' || exit 1

USER 1001
LABEL name={NAME}
LABEL version={VERSION}
This is a fork of someone else's unmaintained repo that i'm trying to update so im not entirely sure what everything does
Brody
Brody10mo ago
change the line with the ENTRYPOINT to
CMD /venv/bin/waitress-serve --listen=*:$PORT weasyprint_rest:app
CMD /venv/bin/waitress-serve --listen=*:$PORT weasyprint_rest:app
meaniebeanie22
meaniebeanie22OP10mo ago
Not at my computer so raw txt will have to do, but:
ERROR:waitress:Exception while serving /api/v1.0/health

Jan 29 15:24:50
Traceback (most recent call last):

Jan 29 15:24:50
File "/venv/lib/python3.12/site-packages/waitress/channel.py", line 428, in service

Jan 29 15:24:50
task.service()

Jan 29 15:24:50
File "/venv/lib/python3.12/site-packages/waitress/task.py", line 168, in service

Jan 29 15:24:50
self.execute()

Jan 29 15:24:50
File "/venv/lib/python3.12/site-packages/waitress/task.py", line 434, in execute

Jan 29 15:24:50
app_iter = self.channel.server.application(environ, start_response)

Jan 29 15:24:50
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 29 15:24:50
TypeError: app() takes 0 positional arguments but 2 were given
ERROR:waitress:Exception while serving /api/v1.0/health

Jan 29 15:24:50
Traceback (most recent call last):

Jan 29 15:24:50
File "/venv/lib/python3.12/site-packages/waitress/channel.py", line 428, in service

Jan 29 15:24:50
task.service()

Jan 29 15:24:50
File "/venv/lib/python3.12/site-packages/waitress/task.py", line 168, in service

Jan 29 15:24:50
self.execute()

Jan 29 15:24:50
File "/venv/lib/python3.12/site-packages/waitress/task.py", line 434, in execute

Jan 29 15:24:50
app_iter = self.channel.server.application(environ, start_response)

Jan 29 15:24:50
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 29 15:24:50
TypeError: app() takes 0 positional arguments but 2 were given
meaniebeanie22
meaniebeanie22OP10mo ago
GitHub
GitHub - meaniebeanie22/weasyprint-rest: The best WeasyPrint contai...
The best WeasyPrint container that exists on the web. :fire: :fire: - GitHub - meaniebeanie22/weasyprint-rest: The best WeasyPrint container that exists on the web. :fire:
Solution
Brody
Brody10mo ago
try this instead
CMD /venv/bin/waitress-serve --port=$PORT --call weasyprint_rest:app
CMD /venv/bin/waitress-serve --port=$PORT --call weasyprint_rest:app
I'm just guessing though
meaniebeanie22
meaniebeanie22OP10mo ago
Seems to work - cheers mate!
Brody
Brody10mo ago
oh wow that was a good guess then
Want results from more Discord servers?
Add your server