最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Trouble setting PORT in DjangoHeroku Procfile using Waitress - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Mar 30 at 0:39 relp lamfred asked Mar 29 at 22:34 relp lamfredrelp lamfred 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Explicitly tell you django-environs library that you are passing int not string. You can achieve that by casting the value in this format, so update your code on settings.py to look like this;

Remove the dollar sign ($) on your .env as well. Then rerun your build process.

PORT = env.int("PORT")
发布评论

评论列表(0)

  1. 暂无评论