[Python] Trouble setting PORT in Django/Heroku Procfile using Waitress

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to deploy my Django application with Heroku (on Windows), and using Waitress (because Gunicorn no longer runs on Windows??). When I hard coded the PORT number, I was able to run it fine.

    When I try to define PORT in the Procfile as an environment variable

    Procfile:

    web: waitress-serve --port=$PORT [projectname].wsgi:application


    from .env

    WEB_CONCURRENCY=2
    PORT=$PORT


    from settings.py

    import environ
    from environ import Env
    env = Env()
    ...
    PORT = env('PORT')


    running "heroku local" produces

    ValueError: invalid literal for int() with base 10: '$PORT'


    Ultimately I'm trying to resolve a failure to bind to PORT:

    Error R10 (Boot timeout) -> Web process failed to bind to $PORT `within 60 seconds of launch`


    I keep seeing mention that "$PORT" is not appropriate for Windows. However I can't figure out what I'm missing. I've seen suggestions that "%PORT%" would work for Windows, but I haven't had success. I've also tried "PORT" without symbols (as the Waitress docs seem to suggest). If there is a Windows friendly syntax, would I need to use it in both .env and Procfile?

    Continue reading...

Compartilhe esta Página