title: App runs locally but crashes when deployed to Heroku
body: <p>My Python Flask app runs locally but when I deploy it to Heroku it successfully builds but crashes when opening the app. I'm relatively comfortable with Python but new to web dev and Heroku etc.</p>
  <p>Here's my Procfile</p>
  <pre><code>web: gunicorn app:app
  </code></pre>
  <p>From my limited understanding my Procfile is correct(?) as it's telling Heroku to run my app.py file which is what I run when running the app locally.</p>
  <p>Logs</p>
  <pre><code>2022-07-14T09:08:18.969324+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/werkzeug/serving.py&quot;, line 740, in __init__
  2022-07-14T09:08:18.969325+00:00 app[web.1]:     HTTPServer.__init__(self, server_address, handler)
  2022-07-14T09:08:18.969325+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/socketserver.py&quot;, line 452, in __init__
  2022-07-14T09:08:18.969325+00:00 app[web.1]:     self.server_bind()
  2022-07-14T09:08:18.969325+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/http/server.py&quot;, line 136, in server_bind
  2022-07-14T09:08:18.969325+00:00 app[web.1]:     socketserver.TCPServer.server_bind(self)
  2022-07-14T09:08:18.969326+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/socketserver.py&quot;, line 466, in server_bind
  2022-07-14T09:08:18.969326+00:00 app[web.1]:     self.socket.bind(self.server_address)
  2022-07-14T09:08:18.969326+00:00 app[web.1]: OSError: [Errno 98] Address already in use
  2022-07-14T09:08:18.969552+00:00 app[web.1]: [2022-07-14 09:08:18 +0000] [10] [INFO] Worker exiting (pid: 10)
  2022-07-14T09:08:33.000000+00:00 app[api]: Build succeeded
  2022-07-14T09:08:49.139858+00:00 app[web.1]: [2022-07-14 09:08:49 +0000] [4] [INFO] Shutting down: Master
  2022-07-14T09:08:49.139897+00:00 app[web.1]: [2022-07-14 09:08:49 +0000] [4] [INFO] Reason: Worker failed to boot.
  2022-07-14T09:08:49.288295+00:00 heroku[web.1]: Process exited with status 3
  2022-07-14T09:08:49.375710+00:00 heroku[web.1]: State changed from up to crashed
  2022-07-14T09:08:49.378964+00:00 heroku[web.1]: State changed from crashed to starting
  2022-07-14T09:08:59.395728+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
  2022-07-14T09:09:00.585739+00:00 app[web.1]: [2022-07-14 09:09:00 +0000] [4] [INFO] Starting gunicorn 20.0.4
  2022-07-14T09:09:00.586046+00:00 app[web.1]: [2022-07-14 09:09:00 +0000] [4] [INFO] Listening at: http://0.0.0.0:33318 (4)
  2022-07-14T09:09:00.586099+00:00 app[web.1]: [2022-07-14 09:09:00 +0000] [4] [INFO] Using worker: sync
  2022-07-14T09:09:00.588900+00:00 app[web.1]: [2022-07-14 09:09:00 +0000] [9] [INFO] Booting worker with pid: 9
  2022-07-14T09:09:00.652265+00:00 app[web.1]: [2022-07-14 09:09:00 +0000] [10] [INFO] Booting worker with pid: 10
  2022-07-14T09:09:01.088879+00:00 heroku[web.1]: State changed from starting to up
  2022-07-14T09:09:01.867617+00:00 app[web.1]: [2022-07-14 09:09:01 +0000] [10] [ERROR] Exception in worker process
  2022-07-14T09:09:01.867618+00:00 app[web.1]: Traceback (most recent call last):
  2022-07-14T09:09:01.867619+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py&quot;, line 583, in spawn_worker
  2022-07-14T09:09:01.867620+00:00 app[web.1]:     worker.init_process()
  2022-07-14T09:09:01.867620+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py&quot;, line 119, in init_process
  2022-07-14T09:09:01.867621+00:00 app[web.1]:     self.load_wsgi()
  2022-07-14T09:09:01.867621+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py&quot;, line 144, in load_wsgi
  2022-07-14T09:09:01.867621+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
  2022-07-14T09:09:01.867622+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py&quot;, line 67, in wsgi
  2022-07-14T09:09:01.867622+00:00 app[web.1]:     self.callable = self.load()
  2022-07-14T09:09:01.867623+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py&quot;, line 49, in load
  2022-07-14T09:09:01.867623+00:00 app[web.1]:     return self.load_wsgiapp()
  2022-07-14T09:09:01.867623+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py&quot;, line 39, in load_wsgiapp
  2022-07-14T09:09:01.867624+00:00 app[web.1]:     return util.import_app(self.app_uri)
  2022-07-14T09:09:01.867624+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py&quot;, line 358, in import_app
  2022-07-14T09:09:01.867624+00:00 app[web.1]:     mod = importlib.import_module(module)
  2022-07-14T09:09:01.867625+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/importlib/__init__.py&quot;, line 127, in import_module
  2022-07-14T09:09:01.867625+00:00 app[web.1]:     return _bootstrap._gcd_import(name[level:], package, level)
  2022-07-14T09:09:01.867625+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1030, in _gcd_import
  2022-07-14T09:09:01.867626+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1007, in _find_and_load
  2022-07-14T09:09:01.867626+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 986, in _find_and_load_unlocked
  2022-07-14T09:09:01.867626+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 680, in _load_unlocked
  2022-07-14T09:09:01.867627+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 850, in exec_module
  2022-07-14T09:09:01.867627+00:00 app[web.1]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 228, in _call_with_frames_removed
  2022-07-14T09:09:01.867627+00:00 app[web.1]:   File &quot;/app/app.py&quot;, line 84, in &lt;module&gt;
  2022-07-14T09:09:01.867628+00:00 app[web.1]:     flask_app.run()
  2022-07-14T09:09:01.867628+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/flask/app.py&quot;, line 990, in run
  2022-07-14T09:09:01.867628+00:00 app[web.1]:     run_simple(host, port, self, **options)
  2022-07-14T09:09:01.867629+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/werkzeug/serving.py&quot;, line 1052, in run_simple
  2022-07-14T09:09:01.867629+00:00 app[web.1]:     inner()
  2022-07-14T09:09:01.867630+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/werkzeug/serving.py&quot;, line 996, in inner
  2022-07-14T09:09:01.867630+00:00 app[web.1]:     srv = make_server(
  2022-07-14T09:09:01.867630+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/werkzeug/serving.py&quot;, line 847, in make_server
  2022-07-14T09:09:01.867630+00:00 app[web.1]:     return ThreadedWSGIServer(
  2022-07-14T09:09:01.867631+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/werkzeug/serving.py&quot;, line 740, in __init__
  2022-07-14T09:09:01.867631+00:00 app[web.1]:     HTTPServer.__init__(self, server_address, handler)
  2022-07-14T09:09:01.867631+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/socketserver.py&quot;, line 452, in __init__
  2022-07-14T09:09:01.867632+00:00 app[web.1]:     self.server_bind()
  2022-07-14T09:09:01.867632+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/http/server.py&quot;, line 136, in server_bind
  2022-07-14T09:09:01.867632+00:00 app[web.1]:     socketserver.TCPServer.server_bind(self)
  2022-07-14T09:09:01.867632+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.9/socketserver.py&quot;, line 466, in server_bind
  2022-07-14T09:09:01.867633+00:00 app[web.1]:     self.socket.bind(self.server_address)
  2022-07-14T09:09:01.867633+00:00 app[web.1]: OSError: [Errno 98] Address already in use
  2022-07-14T09:09:01.867816+00:00 app[web.1]: [2022-07-14 09:09:01 +0000] [10] [INFO] Worker exiting (pid: 10)
  2022-07-14T09:09:32.290539+00:00 heroku[web.1]: Process exited with status 3
  2022-07-14T09:09:32.364652+00:00 heroku[web.1]: State changed from up to crashed
  2022-07-14T09:09:32.118236+00:00 app[web.1]: [2022-07-14 09:09:32 +0000] [4] [INFO] Shutting down: Master
  2022-07-14T09:09:32.118291+00:00 app[web.1]: [2022-07-14 09:09:32 +0000] [4] [INFO] Reason: Worker failed to boot.
  </code></pre>
  <p>Any help would be greatly appreciated!</p>