Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Internal Server Error" deploying Django app to Heroku

Tags:

django

heroku

I have a Django app that I'm trying to deploy to Heroku. I've followed the Heroku documentation closely with no real issues. However, after pushing to Heroku, I'm seeing an "internal server error" when I visit the app online. I'm not seeing any obvious errors in the Terminal (below). This is my first time using Heroku so there is probably a rookie mistake somewhere. Help is appreciated.

(venv)suraj-kapoors-computer:listing surajkapoor$ 
(venv)suraj-kapoors-computer:listing surajkapoor$ 
(venv)suraj-kapoors-computer:listing surajkapoor$ pip freeze > requirements.txt
(venv)suraj-kapoors-computer:listing surajkapoor$ venv
-bash: venv: command not found
(venv)suraj-kapoors-computer:listing surajkapoor$ git init
Initialized empty Git repository in /Users/surajkapoor/Desktop/listing/.git/
(venv)suraj-kapoors-computer:listing surajkapoor$ git add .
(venv)suraj-kapoors-computer:listing surajkapoor$ git commit -m "listings"
[master (root-commit) 62e03eb] listings
 38 files changed, 939 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 Procfile
 create mode 100644 listing/__init__.py
 create mode 100644 listing/settings.py
 create mode 100644 listing/urls.py
 create mode 100644 listing/wsgi.py
 create mode 100644 manage.py
 create mode 100644 noticeboard/__init__.py
 create mode 100644 noticeboard/admin.py
 create mode 100644 noticeboard/media/images/717c798f-8c99-4bd2-b78d-59959b219aa1-620x372.jpeg
 create mode 100644 noticeboard/media/images/717c798f-8c99-4bd2-b78d-59959b219aa1-620x372_1.jpeg
 create mode 100644 noticeboard/media/images/717c798f-8c99-4bd2-b78d-59959b219aa1-620x372_2.jpeg
 create mode 100644 noticeboard/media/images/images-1.jpeg
 create mode 100644 noticeboard/media/images/images-2.jpeg
 create mode 100644 noticeboard/media/images/images.jpeg
 create mode 100644 noticeboard/media/images/images_1.jpeg
 create mode 100644 noticeboard/media/images/imgres-1.jpeg
 create mode 100644 noticeboard/media/images/imgres-2.jpeg
 create mode 100644 noticeboard/media/images/imgres.jpeg
 create mode 100644 noticeboard/media/images/imgres_1.jpeg
 create mode 100644 noticeboard/media/images/imgres_2.jpeg
 create mode 100644 noticeboard/media/images/imgres_3.jpeg
 create mode 100644 noticeboard/media/images/imgres_4.jpeg
 create mode 100644 noticeboard/migrations/0001_initial.py
 create mode 100644 noticeboard/migrations/0002_auto__add_field_listings_image.py
 create mode 100644 noticeboard/migrations/0003_auto__add_gallery__chg_field_listings_image__add_index_listings_image.py
 create mode 100644 noticeboard/migrations/0004_auto__del_gallery__del_field_listings_image__add_field_listings_image1.py
 create mode 100644 noticeboard/migrations/__init__.py
 create mode 100644 noticeboard/models.py
 create mode 100644 noticeboard/static/noticeboard/button.jpg
 create mode 100644 noticeboard/static/noticeboard/left-scroll.jpg
 create mode 100644 noticeboard/static/noticeboard/main.css
 create mode 100644 noticeboard/static/noticeboard/main.js
 create mode 100644 noticeboard/static/noticeboard/right-scroll.jpg
 create mode 100644 noticeboard/templates/listings/index.html
 create mode 100644 noticeboard/templates/listings/listings_detail.html
 create mode 100644 noticeboard/tests.py
 create mode 100644 noticeboard/urls.py
 create mode 100644 noticeboard/views.py
 create mode 100644 os.path.join(BASE_DIR, 'db.sqlite3')
 create mode 100644 requirements.txt
(venv)suraj-kapoors-computer:listing surajkapoor$ heroku create
/Users/surajkapoor/.heroku/client/lib/heroku/updater.rb:164: warning: Insecure world writable dir /Users/surajkapoor/Desktop/listing in PATH, mode 040777
Creating thawing-wildwood-4650... done, stack is cedar
http://thawing-wildwood-4650.herokuapp.com/ | [email protected]:thawing-wildwood-4650.git
Git remote heroku added
(venv)suraj-kapoors-computer:listing surajkapoor$ git push heroku master
Warning: Permanently added the RSA host key for IP address '50.19.85.156' to the list of known hosts.
Counting objects: 45, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (39/39), done.
Writing objects: 100% (45/45), 195.76 KiB | 53 KiB/s, done.
Total 45 (delta 6), reused 0 (delta 0)

-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Preparing Python runtime (python-2.7.4)
-----> Installing Distribute (0.6.36)
-----> Installing Pip (1.3.1)
-----> Installing dependencies using Pip (1.3.1)
       Downloading/unpacking Django==1.5.1 (from -r requirements.txt (line 1))
         Running setup.py egg_info for package Django

       Downloading/unpacking distribute==0.6.34 (from -r requirements.txt (line 2))
         Running setup.py egg_info for package distribute

       Downloading/unpacking dj-database-url==0.2.1 (from -r requirements.txt (line 3))
         Downloading dj-database-url-0.2.1.tar.gz
         Running setup.py egg_info for package dj-database-url

       Downloading/unpacking django-toolbelt==0.0.1 (from -r requirements.txt (line 4))
         Downloading django-toolbelt-0.0.1.tar.gz
         Running setup.py egg_info for package django-toolbelt

       Downloading/unpacking gunicorn==17.5 (from -r requirements.txt (line 5))
         Running setup.py egg_info for package gunicorn

       Downloading/unpacking psycopg2 (from django-toolbelt==0.0.1->-r requirements.txt (line 4))
         Running setup.py egg_info for package psycopg2

       Downloading/unpacking dj-static (from django-toolbelt==0.0.1->-r requirements.txt (line 4))
         Downloading dj-static-0.0.5.tar.gz
         Running setup.py egg_info for package dj-static

       Downloading/unpacking static (from dj-static->django-toolbelt==0.0.1->-r requirements.txt (line 4))
         Downloading static-0.4.tar.gz
         Running setup.py egg_info for package static

       Installing collected packages: Django, distribute, dj-database-url, django-toolbelt, gunicorn, psycopg2, dj-static, static
         Running setup.py install for Django
           changing mode of build/scripts-2.7/django-admin.py from 600 to 755

           changing mode of /app/.heroku/python/bin/django-admin.py to 755
         Found existing installation: distribute 0.6.36
           Uninstalling distribute:
             Successfully uninstalled distribute
         Running setup.py install for distribute
           Before install bootstrap.
           Scanning installed packages
           Setuptools installation detected at /app/.heroku/python/lib/python2.7/site-packages
           Non-egg installation
           Moving elements out of the way...
           Already patched.
           /app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info already patched.

           Installing easy_install script to /app/.heroku/python/bin
           Installing easy_install-2.7 script to /app/.heroku/python/bin
           After install bootstrap.
           /app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info already exists
         Running setup.py install for dj-database-url

         Running setup.py install for django-toolbelt

         Running setup.py install for gunicorn

           Installing gunicorn_paster script to /app/.heroku/python/bin
           Installing gunicorn script to /app/.heroku/python/bin
           Installing gunicorn_django script to /app/.heroku/python/bin
         Running setup.py install for psycopg2
           building 'psycopg2._psycopg' extension
           gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -

         Running setup.py install for dj-static

         Running setup.py install for static

           Installing static script to /app/.heroku/python/bin
       Successfully installed Django distribute dj-database-url django-toolbelt gunicorn psycopg2 dj-static static
       Cleaning up...

-----> Discovering process types
       Procfile declares types -> web

-----> Compiled slug size: 30.2MB
-----> Launching... done, v3
       http://thawing-wildwood-4650.herokuapp.com deployed to Heroku

To [email protected]:thawing-wildwood-4650.git
 * [new branch]      master -> master
(venv)suraj-kapoors-computer:listing surajkapoor$ heroku ps:scale web=1
/Users/surajkapoor/.heroku/client/lib/heroku/helpers.rb:103: warning: Insecure world writable dir /Users/surajkapoor/Desktop/listing in PATH, mode 040777
Scaling web dynos... done, now running 1
(venv)suraj-kapoors-computer:listing surajkapoor$ heroku ps
/Users/surajkapoor/.heroku/client/lib/heroku/helpers.rb:103: warning: Insecure world writable dir /Users/surajkapoor/Desktop/listing in PATH, mode 040777
=== web (1X): `gunicorn listing.wsgi`
web.1: up 2013/07/23 15:49:12 (~ 1m ago)

(venv)suraj-kapoors-computer:listing surajkapoor$ heroku open
/Users/surajkapoor/.heroku/client/lib/heroku/helpers.rb:103: warning: Insecure world writable dir /Users/surajkapoor/Desktop/listing in PATH, mode 040777
Opening thawing-wildwood-4650... done
(venv)suraj-kapoors-computer:listing surajkapoor$  

Heroku Logs show the following:

2013-07-23T17:16:01.137746+00:00 app[web.1]:     return node.render(context)
2013-07-23T17:16:01.138196+00:00 app[web.1]:     pieces.append(force_text(getattr(self, piece)()))
2013-07-23T17:16:01.138196+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/encoding.py", line 99, in force_text
2013-07-23T17:16:01.138196+00:00 app[web.1]:     s = s.__unicode__()
2013-07-23T17:16:01.138433+00:00 app[web.1]:     default_translation = _fetch(settings.LANGUAGE_CODE)
2013-07-23T17:16:01.138433+00:00 app[web.1]:     return _trans.ugettext(message)
2013-07-23T17:16:01.138433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 276, in ugettext
2013-07-23T17:16:01.138433+00:00 app[web.1]:     return do_translate(message, 'ugettext')
2013-07-23T17:16:01.138433+00:00 app[web.1]:     return func(*self.__args, **self.__kw)
2013-07-23T17:16:01.138433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/functional.py", line 130, in __text_cast
2013-07-23T17:16:01.138433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 258, in do_translate
2013-07-23T17:16:01.138433+00:00 app[web.1]:     _default = translation(settings.LANGUAGE_CODE)
2013-07-23T17:16:01.138433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 172, in translation
2013-07-23T17:16:01.138433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 71, in ugettext
2013-07-23T17:16:01.138882+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 154, in _fetch
2013-07-23T17:16:01.138882+00:00 app[web.1]:     app = import_module(appname)
2013-07-23T17:16:01.138882+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-07-23T17:16:01.138882+00:00 app[web.1]:     __import__(name)
2013-07-23T17:16:01.138882+00:00 app[web.1]: ImportError: No module named south
2013-07-23T17:16:01.445966+00:00 app[web.1]:     response = middleware_method(request)
2013-07-23T17:16:01.445966+00:00 app[web.1]: Internal Server Error: /favicon.ico
2013-07-23T17:16:01.445966+00:00 app[web.1]: Traceback (most recent call last):
2013-07-23T17:16:01.445966+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 92, in get_response
2013-07-23T17:16:01.445966+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/middleware/common.py", line 69, in process_request
2013-07-23T17:16:01.445966+00:00 app[web.1]:     if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
2013-07-23T17:16:01.445966+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 551, in is_valid_path
2013-07-23T17:16:01.445966+00:00 app[web.1]:     resolve(path, urlconf)
2013-07-23T17:16:01.445966+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 440, in resolve
2013-07-23T17:16:01.445966+00:00 app[web.1]:     return get_resolver(urlconf).resolve(path)
2013-07-23T17:16:01.446344+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 319, in resolve
2013-07-23T17:16:01.446344+00:00 app[web.1]:     for pattern in self.url_patterns:
2013-07-23T17:16:01.446344+00:00 app[web.1]:     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
2013-07-23T17:16:01.446344+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
2013-07-23T17:16:01.446344+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
2013-07-23T17:16:01.446691+00:00 app[web.1]:   File "/app/noticeboard/models.py", line 2, in <module>
2013-07-23T17:16:01.446691+00:00 app[web.1]:     from django_extensions.db.fields import AutoSlugField
2013-07-23T17:16:01.446344+00:00 app[web.1]:     self._urlconf_module = import_module(self.urlconf_name)
2013-07-23T17:16:01.446344+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-07-23T17:16:01.446344+00:00 app[web.1]:     __import__(name)
2013-07-23T17:16:01.446344+00:00 app[web.1]:   File "/app/listing/urls.py", line 3, in <module>
2013-07-23T17:16:01.446344+00:00 app[web.1]:     from noticeboard import views
2013-07-23T17:16:01.446691+00:00 app[web.1]:   File "/app/noticeboard/views.py", line 2, in <module>
2013-07-23T17:16:01.446691+00:00 app[web.1]:     from noticeboard.models import Listings
2013-07-23T17:16:01.446691+00:00 app[web.1]: ImportError: No module named django_extensions.db.fields
2013-07-23T17:16:01.611717+00:00 app[web.1]: Traceback (most recent call last):
2013-07-23T17:16:01.615024+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=thawing-wildwood-4650.herokuapp.com fwd="79.121.160.251" dyno=web.1 connect=3ms service=175ms status=500 bytes=135
2013-07-23T17:16:01.611717+00:00 app[web.1]: 2013-07-23 12:16:01 [7] [ERROR] Error handling request
2013-07-23T17:16:01.611717+00:00 app[web.1]:     respiter = self.wsgi(environ, resp.start_response)
2013-07-23T17:16:01.611963+00:00 app[web.1]:     return debug.technical_500_response(request, *exc_info)
2013-07-23T17:16:01.611963+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/views/debug.py", line 69, in technical_500_response
2013-07-23T17:16:01.611963+00:00 app[web.1]:     html = reporter.get_traceback_html()
2013-07-23T17:16:01.611963+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/views/debug.py", line 298, in get_traceback_html
2013-07-23T17:16:01.611717+00:00 app[web.1]:     return self.application(environ, start_response)
2013-07-23T17:16:01.611717+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/dj_static.py", line 59, in __call__
2013-07-23T17:16:01.611717+00:00 app[web.1]:     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2013-07-23T17:16:01.611717+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
2013-07-23T17:16:01.611717+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
2013-07-23T17:16:01.611717+00:00 app[web.1]:     response = self.get_response(request)
2013-07-23T17:16:01.611963+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 217, in handle_uncaught_exception
2013-07-23T17:16:01.611717+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 126, in handle_request
2013-07-23T17:16:01.612261+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node
2013-07-23T17:16:01.611963+00:00 app[web.1]:     return t.render(c)
2013-07-23T17:16:01.611963+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py", line 140, in render
2013-07-23T17:16:01.611963+00:00 app[web.1]:     return self._render(context)
2013-07-23T17:16:01.611963+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
2013-07-23T17:16:01.612261+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py", line 830, in render
2013-07-23T17:16:01.612261+00:00 app[web.1]:     bit = self.render_node(node, context)
2013-07-23T17:16:01.611963+00:00 app[web.1]:     return self.nodelist.render(context)
2013-07-23T17:16:01.612261+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/defaultfilters.py", line 715, in date
2013-07-23T17:16:01.612261+00:00 app[web.1]:     return format(value, arg)
2013-07-23T17:16:01.612987+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/dateformat.py", line 312, in format
2013-07-23T17:16:01.612261+00:00 app[web.1]:     return node.render(context)
2013-07-23T17:16:01.612261+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/debug.py", line 84, in render
2013-07-23T17:16:01.612987+00:00 app[web.1]:     pieces.append(force_text(getattr(self, piece)()))
2013-07-23T17:16:01.612987+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/dateformat.py", line 216, in r
2013-07-23T17:16:01.612987+00:00 app[web.1]:     return self.format('D, j M Y H:i:s O')
2013-07-23T17:16:01.612261+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py", line 606, in resolve
2013-07-23T17:16:01.612261+00:00 app[web.1]:     new_obj = func(obj, *arg_vals)
2013-07-23T17:16:01.612987+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/encoding.py", line 99, in force_text
2013-07-23T17:16:01.613230+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 71, in ugettext
2013-07-23T17:16:01.613230+00:00 app[web.1]:     return _trans.ugettext(message)
2013-07-23T17:16:01.613230+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 276, in ugettext
2013-07-23T17:16:01.613230+00:00 app[web.1]:     return do_translate(message, 'ugettext')
2013-07-23T17:16:01.612987+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/dateformat.py", line 35, in format
2013-07-23T17:16:01.612987+00:00 app[web.1]:     return df.format(format_string)
2013-07-23T17:16:01.612987+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/dateformat.py", line 35, in format
2013-07-23T17:16:01.612987+00:00 app[web.1]:     pieces.append(force_text(getattr(self, piece)()))
2013-07-23T17:16:01.612987+00:00 app[web.1]:     s = s.__unicode__()
2013-07-23T17:16:01.613230+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/functional.py", line 130, in __text_cast
2013-07-23T17:16:01.613230+00:00 app[web.1]:     return func(*self.__args, **self.__kw)
2013-07-23T17:16:01.613230+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 258, in do_translate
2013-07-23T17:16:01.613230+00:00 app[web.1]:     _default = translation(settings.LANGUAGE_CODE)
2013-07-23T17:16:01.613230+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 172, in translation
2013-07-23T17:16:01.613230+00:00 app[web.1]:     default_translation = _fetch(settings.LANGUAGE_CODE)
2013-07-23T17:16:01.613573+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 154, in _fetch
2013-07-23T17:16:01.613573+00:00 app[web.1]:     app = import_module(appname)
2013-07-23T17:16:01.613573+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-07-23T17:16:01.613573+00:00 app[web.1]:     __import__(name)
2013-07-23T17:16:01.613573+00:00 app[web.1]: ImportError: No module named south
2013-07-23T17:16:01.612261+00:00 app[web.1]:     output = self.filter_expression.resolve(context)
2013-07-23T17:16:01.142419+00:00 heroku[router]: at=info method=GET path=/ host=thawing-wildwood-4650.herokuapp.com fwd="79.121.160.251" dyno=web.1 connect=2ms service=246ms status=500 bytes=135
(venv)suraj-kapoors-computer:listing surajkapoor$ 
like image 802
Suraj Kapoor Avatar asked Jul 23 '13 15:07

Suraj Kapoor


2 Answers

Can you please provide the output of the command

heroku logs --app YOUR_APP_NAME

and set DEBUG=True on settings.py ?

It seems to be a valid deploy with an application error.

EDIT FROM THE COMMENTS:

South and DjangoExtension.db.fields modules are missing.

Add the missing libraries to the last line of requirements.txt and redeploy your app. Heroku deploy stack will run the command:

pip install -r requirements.txt

And install all the entries on your environment.

like image 136
André Teixeira Avatar answered Nov 15 '22 05:11

André Teixeira


The problem might also be that you have misconfigured your wsgi.py.

I was stuck with the same problem. For me the problem was in my_project/wsgi.py . I had setup 3 settings file under my_project/my_project/settings folder and I had configured the necessary configuration under manage.py to detect the setting file but forgot the configuration under my_project/wsgi.py . So resolving this solved the problem for me.

like image 22
Nirzal Avatar answered Nov 15 '22 03:11

Nirzal