0

I use Procfile with web: python manage.py runserver '0.0.0.0:$PORT' first time it started successfully, but after first git push it crashed with this error:

OperationalError at /

could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?

restarting webrunner did not help. What's the trick? heroku logs output:

2013-11-25T23:39:56.725138+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
2013-11-25T23:39:56.725138+00:00 app[web.1]:     conn = _connect(dsn, connection_factory=connection_factory, async=async)
2013-11-25T23:39:56.725138+00:00 app[web.1]: OperationalError: could not connect to server: Connection refused
2013-11-25T23:39:56.725138+00:00 app[web.1]:    Is the server running on host "127.0.0.1" and accepting
2013-11-25T23:39:56.725138+00:00 app[web.1]:    TCP/IP connections on port 5432?
2013-11-25T23:39:56.725138+00:00 app[web.1]:     return Database.connect(**conn_params)
2013-11-25T23:39:56.725138+00:00 app[web.1]: 
2013-11-25T23:39:56.872620+00:00 app[web.1]: [26/Nov/2013 00:39:56] "GET / HTTP/1.1" 500 118846

using gunicorn its says that can't find gunicorn app and app[web.1]: bash: gunicorn: command not found and heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=shrouded-falls-4631.herokuapp.com fwd="188.163.187.182" dyno= connect= service= status=503 bytes= from heroku logs and heroku ps shows crashed app[web]. Using djangos' runserver at least started at first time. But then also got crashed.

boldnik
  • 2,547
  • 2
  • 27
  • 32

3 Answers3

0

I do not know the exact reason, but why are you running django's runserver on heroku? Heroku uses gunicorn, which can execute the .wsgi files in your project_name/project_name folder.

Instead, use: "web: gunicorn recipe.wsgi" in the procfile, so gunicorn serves your django app. Just my 2 cents.

Also, it seems if you use 0.0.0.0:5432 or 127.0.0.1:5432, it might work.

user2707389
  • 817
  • 6
  • 12
  • using gunicorn its says that can't find gunicorn app and `app[web.1]: bash: gunicorn: command not found` and `heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=shrouded-falls-4631.herokuapp.com fwd="188.163.187.182" dyno= connect= service= status=503 bytes=` from heroku logs and heroku ps shows crashed app[web]. Using djangos' runserver at least started at first time. But then also got crashed. – boldnik Nov 26 '13 at 15:37
  • 1
    If you follow the django on heroku tutorial on heroku's website, you will see that you have to make requirements.txt file, and gunicorn is a requirement. For example, for my last work, the requirements.txt had the following requirements: Django==1.6 argparse==1.2.1 boto==2.16.0 django-ckeditor==4.0.2 django-registration==1.0 PIL==1.1.7 Pillow==2.2.1 South==0.8.2 static==0.4 dj-database-url==0.2.2 dj-static==0.0.5 django-storages==1.1.8 gunicorn==18.0 psycopg2==2.5.1 wsgiref==0.1.2 – user2707389 Nov 26 '13 at 18:21
  • I have already `-r requirements/develop.txt` in `requirements.txt` in the core folder. I guess it should catch it the same way it does for local machine. – boldnik Nov 27 '13 at 10:34
  • Just weird why it installed from requirements.txt only for explicit declaration of apps in it, but didn't do this for `-r` – boldnik Nov 27 '13 at 11:13
0

Your database is not connected. Make sure you set the proper DATABASE_URL environment variable, and that you actually have a postgres plan active.

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
  • DATABASE_URL is set and I do not think this is the reason, because it says that it fails on starting gunicorn. But thanks for reply. – boldnik Nov 27 '13 at 10:39
0

Thanks @user2707389, it really works only with all apps declared in requirements.txt but I don't get it why it doesn't with -r option. Anyway, fixing further Procfile and correct wsgi.py made it alive.

boldnik
  • 2,547
  • 2
  • 27
  • 32