deploy Django2 on heroku , but can not open the webpage in browsers - django

I did a django project on python, and push it to heroku, but when I try to access it with
https://desolate-oasis-71960.herokuapp.com
browser can not load it.
I use django2.1.3 on python3, here is my settings.py:
import os
import django_heroku
# Build paths inside the project like this:os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
--snip-
# Activate Django-Heroku.
django_heroku.settings(locals())
#setting Heroku
cwd = os.getcwd()
if cwd == '/app' or cwd[:4] == '/tmp':
import dj_database_url
DATABASES= {
'default': dj_database_url.config(default='postgres://localhost')
}
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO','https')
#ALLOWED_HOSTS = ['*']
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'static'),
)
but after I push the project to heroku ,I can not open the webpage, then I run the command: heroku logs, here is the log :
2018-11-16T03:47:55.000000+00:00 app[api]: Build succeeded
2018-11-16T03:48:48.803513+00:00 heroku[router]: at=error code=H14
desc="No web processes running" method=GET path="/"
host=desolate-oasis-71960.herokuapp.com
request_id=703f8297-76f6-4434-9fcc-805c059fd3d8
fwd="202.119.45.10" dyno= connect= service=status=503
bytes=protocol=https
and I also try to load it locally with command
heroku local
the command window always shows like this:
2:52:27 PM web.1 | [2018-11-16 14:52:27 +0800] [1950] [INFO] Starting
gunicorn 19.9.0
2:52:27 PM web.1 | [2018-11-16 14:52:27 +0800] [1950] [INFO] Listening
at: http://0.0.0.0:5000 (1950)
2:52:27 PM web.1 | [2018-11-16 14:52:27 +0800] [1950] [INFO] Using worker: sync
2:52:27 PM web.1 | [2018-11-16 14:52:27 +0800] [1953] [INFO] Booting
worker with pid: 1953
and I need to push "control"+"C" to exit
Help me please

In settings.py:
ALLOWED_HOSTS = ['desolate-oasis-71960.herokuapp.com']

Thanks, I have solved this by re-building Procfile by using command in terminator:
touch .Procfile
and I delete my .git file(have to delete this file),
then re-initialize .git file by command
git init
and it worked.

Related

failed to find 'app' attribute while using gunicorn

I have two files app.py which is in root and the init.py inside a directory named website.
error log:
(vidscript) root#localhost:~# gunicorn --workers 3 --bind 0.0.0.0:8000 vidscript:app
[2023-02-06 17:01:56 +0000] [5272] [INFO] Starting gunicorn 20.1.0
[2023-02-06 17:01:56 +0000] [5272] [INFO] Listening at: http://0.0.0.0:8000 (5272)
[2023-02-06 17:01:56 +0000] [5272] [INFO] Using worker: sync
[2023-02-06 17:01:56 +0000] [5273] [INFO] Booting worker with pid: 5273
Failed to find attribute 'app' in 'vidscript'.
app.py:
from website import create_app
if __name__ == "__main__":
app = create_app()
app.run()
I expected to run the home page while it actually wokers in development server mode using. python app.py

Docker-compose + Heroku + Django + Gunicorn H14 error

I am getting an H14 Heroku error when trying to deploy my built docker image to heroku.
Since the Heroku documentation says a CMD command is required and it appears that the commands in the Procfile are not actually run I am at a bit of a loss as to what to do.
My heroku error log : `
2017-11-01T11:19:47.714787+00:00 app[globus.1]: Post-processed 'admin/css/forms.css' as 'admin/css/forms.2003a066ae02.css'
2017-11-01T11:19:47.715387+00:00 app[globus.1]:
2017-11-01T11:19:47.715389+00:00 app[globus.1]: 0 static files copied to '/globus/staticfiles', 62 unmodified, 24 post-processed.
2017-11-01T11:20:48.337975+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=kolland-globus-1.herokuapp.com request_id=e2a6eda9-e2bf-477b-9987-b5995d110b0e fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T11:20:48.683132+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=kolland-globus-1.herokuapp.com request_id=eb2e00ee-826a-4ddd-aa22-78e242612e8f fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T11:20:48.766644+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=kolland-globus-1.herokuapp.com request_id=60d645a6-8657-4236-80d9-7a8f8e880640 fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
Output of heroku ps:
=== globus (Free): /start.sh (1)
globus.1: up 2017/11/01 13:19:44 +0200 (~ 17m ago)
Heroku Control Panel for the app says:
globus /start.sh
My code is as follows:
1) The start.sh script:
#!/bin/bash
python manage.py migrate # Apply database migrations
python manage.py collectstatic --clear --noinput # clearstatic files
python manage.py collectstatic --noinput # collect static files
# Prepare log files and start outputting logs to stdout
exec gunicorn globus.wsgi --bind 0.0.0.0:$PORT --workers 3
#python manage.py runserver 0.0.0.0:$PORT --settings=globus.settings.production
2) The docker-compose file :
version: '2'
services:
globus:
build: .
image: globus:latest
ports:
- "5000:5000"
env_file: .env
volumes:
- ./globus:/opt/globus
3) Dockerfile:
FROM python:2.7.14
ENV PYTHONUNBUFFERED 1
ADD ./requirements.txt /requirements.txt
ADD ./start.sh /start.sh
ADD . /globus
RUN pip install -r requirements.txt
RUN groupadd -r django && useradd -r -g django django
RUN chown -R django /globus && chmod +x start.sh && chown django start.sh
WORKDIR /globus
CMD ["/start.sh"]
What I've tried ::
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:$PORT", "--settings=globus.settings.production" ]
CMD ["exec", "gunicorn", "globus.wsgi", "-b", "0.0.0.0:$PORT", "--log-file", "-"]
CMD exec gunicorn globus.wsgi -b 0.0.0.0:$PORT --log-file -
CMD ["/start.sh"]
&& ENTRYPOINT ["/start.sh"](without exec gunicorn cmd) + CMD exec gunicorn globus.wsgi -b 0.0.0.0:$PORT
Additionally I've run in the docker-compose file:
command: python manage.py runserver 0.0.0.0:$PORT --settings=globus.settings.production
command: python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT --settings=globus.settings.production
Notes:
**
Running docker-compose build + up locally works for all aforementioned aproaches provided I change $PORT to 5000.
**
I have a feeling it might have something to do with permissions because I am running docker-compose build + up as root user although am not sure how to change the Dockerfile to avoid that beyond the two lines I have added.
dyno= connect= service= in the error logs I believe means that the app is somehow either crashing or not exposed to the heroku router.
The databse is the Heroku Postgresql Addon and the credentials are stored in an env file. The addon works even if I run docker-compose up on my local machine.
I have a working heroku app that was deployed via git.
When I did an:
heroku run bash
> ls
I could see the file structure
When I do the same on for this app I get nothing
Any help would be greatly appreciated!!!
Result of the Netstat command:
2017-11-01T20:50:11.186705+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [6] [INFO] Starting gunicorn 19.7.1
2017-11-01T20:50:11.187111+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [6] [INFO] Listening at: http://0.0.0.0:18815 (6)
2017-11-01T20:50:11.202914+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [12] [INFO] Booting worker with pid: 12
2017-11-01T20:50:11.187194+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [6] [INFO] Using worker: sync
2017-11-01T20:50:11.192252+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [11] [INFO] Booting worker with pid: 11
2017-11-01T20:50:11.247884+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [13] [INFO] Booting worker with pid: 13
2017-11-01T20:50:16.019831+00:00 heroku[globus.1]: Process exited with status 0
2017-11-01T20:50:15.952136+00:00 app[globus.1]: (Not all processes could be identified, non-owned process info
2017-11-01T20:50:15.957398+00:00 app[globus.1]: Active Internet connections (servers and established)
2017-11-01T20:50:15.957400+00:00 app[globus.1]: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
2017-11-01T20:50:15.952156+00:00 app[globus.1]: will not be shown, you would have to be root to see it all.)
2017-11-01T20:50:15.957400+00:00 app[globus.1]: tcp 0 0 0.0.0.0:18815 0.0.0.0:* LISTEN 6/python
2017-11-01T20:50:16.031459+00:00 heroku[globus.1]: State changed from up to crashed
2017-11-01T20:51:19.828010+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=kolland-globus-1.herokuapp.com request_id=59003956-da54-4a6f-921f-70ed4930fc3e fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T20:51:19.652507+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=kolland-globus-1.herokuapp.com request_id=6a090f48-214f-457b-9471-09e2995817fe fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https

heroku $PORT variable in Procfile

Hi have a Django project that I want to deploy on heroku. My procfile looks like this:
web: python subfolder/manage.py runserver $PORT
But my heroku logs tell me that the application did not bind to the port within the required time.
2014-04-17T15:35:20.294741+00:00 heroku[api]: Deploy c456cc6 by my#email.com
2014-04-17T15:35:20.294830+00:00 heroku[api]: Release v17 created by my#email.com
2014-04-17T15:35:31.447035+00:00 heroku[web.1]: Starting process with command `python subfolder/manage.py runserver 14311`
2014-04-17T15:35:32.949252+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '14311']
2014-04-17T15:35:33.286494+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '14311']
2014-04-17T15:35:33.296080+00:00 app[web.1]: Validating models...
2014-04-17T15:35:33.296084+00:00 app[web.1]:
2014-04-17T15:35:33.434037+00:00 app[web.1]: 0 errors found
2014-04-17T15:35:33.434129+00:00 app[web.1]: April 17, 2014 - 10:35:33
2014-04-17T15:35:33.434131+00:00 app[web.1]: Django version 1.6.2, using settings 'subfolder.settings'
2014-04-17T15:35:33.434133+00:00 app[web.1]: Starting development server at http://127.0.0.1:14311/
2014-04-17T15:35:33.434134+00:00 app[web.1]: Quit the server with CONTROL-C.
2014-04-17T15:36:31.995497+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-04-17T15:36:31.995711+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-04-17T15:36:33.512080+00:00 heroku[web.1]: Process exited with status 137
2014-04-17T15:36:33.526505+00:00 heroku[web.1]: State changed from starting to crashed
2014-04-17T15:36:33.527696+00:00 heroku[web.1]: State changed from crashed to starting
2014-04-17T15:36:42.946854+00:00 heroku[web.1]: Starting process with command `python subfolder/manage.py runserver 9192`
2014-04-17T15:36:43.989111+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '9192']
2014-04-17T15:36:44.294956+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '9192']
2014-04-17T15:36:44.302783+00:00 app[web.1]: Validating models...
2014-04-17T15:36:44.302787+00:00 app[web.1]:
2014-04-17T15:36:44.447995+00:00 app[web.1]: 0 errors found
2014-04-17T15:36:44.448008+00:00 app[web.1]: April 17, 2014 - 10:36:44
2014-04-17T15:36:44.448009+00:00 app[web.1]: Django version 1.6.2, using settings 'subfolder.settings'
2014-04-17T15:36:44.448010+00:00 app[web.1]: Starting development server at http://127.0.0.1:9192/
2014-04-17T15:36:44.448012+00:00 app[web.1]: Quit the server with CONTROL-C.
2014-04-17T15:37:43.446630+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-04-17T15:37:43.446759+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-04-17T15:37:43.456335+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=my-app.herokuapp.com request_id=7eed5b88-2bb3-479e-b268-f538742d8ac9 fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
2014-04-17T15:37:44.608835+00:00 heroku[web.1]: Process exited with status 137
2014-04-17T15:37:44.625259+00:00 heroku[web.1]: State changed from starting to crashed
2014-04-17T15:39:18.516212+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=my-app.herokuapp.com request_id=145aa053-bb2b-4570-8ba6-fa88f2a5b1a6 fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
2014-04-17T15:47:22.827631+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=my-app.herokuapp.com request_id=fe43143f-defd-4756-a61c-e9558dd15ae6 fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
2014-04-17T15:57:27.577848+00:00 heroku[web.1]: State changed from crashed to starting
2014-04-17T15:57:37.742542+00:00 heroku[web.1]: Starting process with command `python subfolder/manage.py runserver 10935`
2014-04-17T15:57:39.224244+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '10935']
2014-04-17T15:57:39.788496+00:00 app[web.1]: Django version 1.6.2, using settings 'subfolder.settings'
2014-04-17T15
:57:39.788498+00:00 app[web.1]: Starting development server at http://127.0.0.1:10935/
2014-04-17T15:57:39.618885+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '10935']
2014-04-17T15:57:39.788500+00:00 app[web.1]: Quit the server with CONTROL-C.
2014-04-17T15:57:39.636416+00:00 app[web.1]: Validating models...
2014-04-17T15:57:39.636420+00:00 app[web.1]:
2014-04-17T15:57:39.788202+00:00 app[web.1]: 0 errors found
2014-04-17T15:57:39.788493+00:00 app[web.1]: April 17, 2014 - 10:57:39
2014-04-17T15:58:38.275475+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-04-17T15:58:38.275554+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-04-17T15:58:39.572038+00:00 heroku[web.1]: Process exited with status 137
2014-04-17T15:58:39.588577+00:00 heroku[web.1]: State changed from starting to crashed
2014-04-17T16:04:48.672005+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=my-app.herokuapp.com request_id=fc101c45-45c0-4e46-ad26-a7953619525e fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
It seems like $PORT differs from some time to time. The heroku config however says the following:
(.env) $ heroku config
=== my-app Config Vars
PORT: 33507
Why doesn't it work?
By default the development server binds to localhost only, you must specific that you want to bind to any IP:
web: python subfolder/manage.py runserver 0.0.0.0:$PORT
But running the dev server in production is a very bad idea. You really should be using gunicorn or some other proper server to deploy your project:
web: gunicorn subfolder/yourproject.wsgi
Follow the steps on https://devcenter.heroku.com/articles/getting-started-with-django if you need more guidance.

Heroku Django-Admin 500 Error?

Deployed a new app to Heroku app that runs fine at myapp.herokuapp.com, but throws a 500 Server Error if I try to access the admin backend at myapp.herokuapp.com/admin
INSTALLED_APPS = (
...
'django.contrib.admin',
'gunicorn',
'storages',
# 'django.contrib.admindocs',
)
Here's the log excerpt:
2013-07-10T17:35:28.893320+00:00 heroku[web.1]: Starting process with command `python manage.py run_gunicorn -b 0.0.0.0:27294 -w 3 --log-level info`
2013-07-10T17:35:32.298226+00:00 app[web.1]: 2013-07-10 13:35:32 [2] [INFO] Starting gunicorn 0.17.4
2013-07-10T17:35:32.299005+00:00 app[web.1]: 2013-07-10 13:35:32 [2] [INFO] Using worker: sync
2013-07-10T17:35:32.298932+00:00 app[web.1]: 2013-07-10 13:35:32 [2] [INFO] Listening at: http://0.0.0.0:27294 (2)
2013-07-10T17:35:32.312781+00:00 app[web.1]: 2013-07-10 13:35:32 [11] [INFO] Booting worker with pid: 11
2013-07-10T17:35:32.388874+00:00 app[web.1]: 2013-07-10 13:35:32 [12] [INFO] Booting worker with pid: 12
2013-07-10T17:35:32.495370+00:00 heroku[web.1]: State changed from starting to up
2013-07-10T17:35:32.524196+00:00 app[web.1]: 2013-07-10 13:35:32 [13] [INFO] Booting worker with pid: 13
2013-07-10T17:35:59.929850+00:00 heroku[router]: at=info method=GET path=/ host=myapp.herokuapp.com fwd="64.119.130.116" dyno=web.1 connect=0ms service=190ms status=200 bytes=12220
2013-07-10T17:36:04.363323+00:00 heroku[router]: at=info method=GET path=/admin host=myapp.herokuapp.com fwd="64.119.130.116" dyno=web.1 connect=0ms service=4ms status=301 bytes=5
2013-07-10T17:36:04.872523+00:00 heroku[router]: at=info method=GET path=/admin/ host=myapp.herokuapp.com fwd="64.119.130.116" dyno=web.1 connect=0ms service=481ms status=500 bytes=38
What settings would cause the app to run normally but throw a 500 error on /admin? What am I likely overlooking or missing? Thanks.
Thanks to Magnus' recommendation I added sentry to my project and identified a postgres DatabaseError: relation issue due a project app I hadn't successfully migrated on heroku.
Fix just took a fake and completing the rest of the migration.
heroku run python manage.py migrate app 0016 --fake
heroku run python manage.py migrate
You can add free getsentry addon and receive exception traceback remaining in DEBUG=False in production.
You can also setup plain email notification on errors as admin email.
Without any information about error details it will be hard to give you advice.

unable to run django app using foreman and gunicorn

I am trying to run my django app using gunicorn and foreman. I can successfully run it using python manage.py server. However when running it using forman it fails -
15:32:01 web.1 | started with pid 29188
15:32:01 web.1 | 2012-08-16 15:32:01 [29191] [INFO] Starting gunicorn 0.14.6
15:32:01 web.1 | 2012-08-16 15:32:01 [29191] [INFO] Listening at: http://127.0.0.1:8000 (29191)
15:32:01 web.1 | 2012-08-16 15:32:01 [29191] [INFO] Using worker: sync
15:32:01 web.1 | 2012-08-16 15:32:01 [29194] [INFO] Booting worker with pid: 29194
15:32:01 web.1 | 2012-08-16 15:32:01 [29194] [INFO] Worker exiting (pid: 29194)
15:32:02 web.1 | 2012-08-16 15:32:02 [29191] [INFO] Shutting down: Master
15:32:02 web.1 | 2012-08-16 15:32:02 [29191] [INFO] Reason: Worker failed to boot.
15:32:02 web.1 | exited with code 3
Below is the contents of the Procfile -
web: gunicorn tms.wsgi
I have been following the instructions given on heroku for setting it up.
What instructions are you following? I run Django apps on Heroku using this:
web: python django_project/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3 -k gevent --preload
What directory is your settings.py file located in in which you added 'gunicorn' to your INSTALLED_APPS? I'm assuming you're following the Heroku Getting Started with Django tutorial. The .wsgi file you state in your Procfile should match with that directory which you have your settings.py in.
Your Procfile should be:
web: gunicorn <directory_containing_settings.py_file>.wsgi -b 0.0.0.0:$PORT
If you are facing trouble following the Heroku Documentation then you may check my sample app deployed to Heroku https://github.com/shinigamiryuk/Django-Heroku-Sample-Application