Flask项目部署在heroku上但是应用报错

Flask project deployed on heroku but application error

我已经在 heroku 上部署了我的 flask 项目,但由于某种原因我收到了这个错误

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail

这是尾日志:-

2021-05-24T10:09:53.692145+00:00 app[web.1]: [2021-05-24 10:09:53 +0000] [8] [ERROR] Exception in worker process
2021-05-24T10:09:53.692146+00:00 app[web.1]: Traceback (most recent call last):
2021-05-24T10:09:53.692147+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-05-24T10:09:53.692148+00:00 app[web.1]: worker.init_process()
2021-05-24T10:09:53.692148+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-05-24T10:09:53.692148+00:00 app[web.1]: self.load_wsgi()
2021-05-24T10:09:53.692149+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-05-24T10:09:53.692149+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-05-24T10:09:53.692150+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-05-24T10:09:53.692150+00:00 app[web.1]: self.callable = self.load()
2021-05-24T10:09:53.692150+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-05-24T10:09:53.692151+00:00 app[web.1]: return self.load_wsgiapp()
2021-05-24T10:09:53.692151+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-05-24T10:09:53.692154+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-05-24T10:09:53.692154+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2021-05-24T10:09:53.692155+00:00 app[web.1]: mod = importlib.import_module(module)
2021-05-24T10:09:53.692155+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-05-24T10:09:53.692156+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-05-24T10:09:53.692156+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2021-05-24T10:09:53.692157+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2021-05-24T10:09:53.692157+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2021-05-24T10:09:53.692157+00:00 app[web.1]: ModuleNotFoundError: No module named 'wsgi'
2021-05-24T10:09:53.692947+00:00 app[web.1]: [2021-05-24 10:09:53 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-05-24T10:09:53.724963+00:00 app[web.1]: [2021-05-24 10:09:53 +0000] [4] [WARNING] Worker with pid 8 was terminated due to signal 15
2021-05-24T10:09:53.823313+00:00 app[web.1]: [2021-05-24 10:09:53 +0000] [4] [INFO] Shutting down: Master
2021-05-24T10:09:53.823444+00:00 app[web.1]: [2021-05-24 10:09:53 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-05-24T10:09:53.916842+00:00 heroku[web.1]: Process exited with status 3
2021-05-24T10:09:54.059978+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-24T10:10:47.953222+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gumshuda.herokuapp.com request_id=8ebeec8f-dd4e-428d-9b4d-f0bab713c2c5 fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:49.176461+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gumshuda.herokuapp.com request_id=3715c630-010a-4865-ae98-109eeb883657 fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:49.360422+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gumshuda.herokuapp.com request_id=913381a8-0f54-4b76-9e58-bc234fbddfca fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:50.093228+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gumshuda.herokuapp.com request_id=a6a18d32-6fc8-4107-ab7a-2265ad303aa9 fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:50.335938+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gumshuda.herokuapp.com request_id=727dd28a-4220-4cd0-a359-a0155b1ca03b fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:51.196096+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gumshuda.herokuapp.com request_id=8b04ca83-e9d4-447a-a049-6a656a4a3592 fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:51.507143+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gumshuda.herokuapp.com request_id=8a26218b-7898-4057-bd0e-b5ab60634c7a fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:10:52.086884+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gumshuda.herokuapp.com request_id=e5465c73-f643-4538-9dd0-6f6bf52a813d fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:16:07.000000+00:00 app[api]: Build started by user kakashiii247@gmail.com
2021-05-24T10:16:34.003462+00:00 app[api]: Release v5 created by user kakashiii247@gmail.com
2021-05-24T10:16:34.003462+00:00 app[api]: Deploy 47022151 by user kakashiii247@gmail.com
2021-05-24T10:16:35.052516+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-24T10:16:45.000000+00:00 app[api]: Build succeeded
2021-05-24T10:16:46.404097+00:00 heroku[web.1]: Starting process with command `gunicorn app:run`
2021-05-24T10:16:49.594387+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-05-24T10:16:49.595910+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [4] [INFO] Listening at: http://0.0.0.0:49148 (4)
2021-05-24T10:16:49.595994+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [4] [INFO] Using worker: sync
2021-05-24T10:16:49.608424+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [7] [INFO] Booting worker with pid: 7
2021-05-24T10:16:49.614894+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [7] [ERROR] Exception in worker process
2021-05-24T10:16:49.614896+00:00 app[web.1]: Traceback (most recent call last):
2021-05-24T10:16:49.614911+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-05-24T10:16:49.614912+00:00 app[web.1]: worker.init_process()
2021-05-24T10:16:49.614912+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-05-24T10:16:49.614913+00:00 app[web.1]: self.load_wsgi()
2021-05-24T10:16:49.614913+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-05-24T10:16:49.614914+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-05-24T10:16:49.614914+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-05-24T10:16:49.614914+00:00 app[web.1]: self.callable = self.load()
2021-05-24T10:16:49.614915+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-05-24T10:16:49.614915+00:00 app[web.1]: return self.load_wsgiapp()
2021-05-24T10:16:49.614915+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-05-24T10:16:49.614916+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-05-24T10:16:49.614916+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2021-05-24T10:16:49.614916+00:00 app[web.1]: mod = importlib.import_module(module)
2021-05-24T10:16:49.614917+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-05-24T10:16:49.614918+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-05-24T10:16:49.614918+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2021-05-24T10:16:49.614919+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2021-05-24T10:16:49.614919+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2021-05-24T10:16:49.614919+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
2021-05-24T10:16:49.615070+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-05-24T10:16:49.646178+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [8] [INFO] Booting worker with pid: 8
2021-05-24T10:16:49.652879+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [8] [ERROR] Exception in worker process
2021-05-24T10:16:49.652881+00:00 app[web.1]: Traceback (most recent call last):
2021-05-24T10:16:49.652882+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-05-24T10:16:49.652882+00:00 app[web.1]: worker.init_process()
2021-05-24T10:16:49.652883+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-05-24T10:16:49.652883+00:00 app[web.1]: self.load_wsgi()
2021-05-24T10:16:49.652884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-05-24T10:16:49.652884+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-05-24T10:16:49.652884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-05-24T10:16:49.652885+00:00 app[web.1]: self.callable = self.load()
2021-05-24T10:16:49.652885+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-05-24T10:16:49.652886+00:00 app[web.1]: return self.load_wsgiapp()
2021-05-24T10:16:49.652886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-05-24T10:16:49.652886+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-05-24T10:16:49.652887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2021-05-24T10:16:49.652887+00:00 app[web.1]: mod = importlib.import_module(module)
2021-05-24T10:16:49.652887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-05-24T10:16:49.652888+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-05-24T10:16:49.652888+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2021-05-24T10:16:49.652889+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2021-05-24T10:16:49.652889+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2021-05-24T10:16:49.652890+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
2021-05-24T10:16:49.657164+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-05-24T10:16:49.660096+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [4] [WARNING] Worker with pid 8 was terminated due to signal 15
2021-05-24T10:16:49.760393+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [4] [INFO] Shutting down: Master
2021-05-24T10:16:49.760520+00:00 app[web.1]: [2021-05-24 10:16:49 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-05-24T10:16:49.877682+00:00 heroku[web.1]: Process exited with status 3
2021-05-24T10:16:50.009807+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-24T10:17:44.468866+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gumshuda.herokuapp.com request_id=65996a2c-ef25-48b9-8a14-89b498e93eb8 fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http
2021-05-24T10:17:45.061485+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gumshuda.herokuapp.com request_id=d0440787-e7d1-471e-9640-107365df44a6 fwd="45.112.40.208" dyno= connect= service= status=503 bytes= protocol=http

这是我的 requirement.txt:-

bcrypt==3.2.0
cffi==1.14.5
click==8.0.0
colorama==0.4.4
dnspython==2.1.0
email-validator==1.1.2
Flask==2.0.0
Flask-Bcrypt==0.7.1
Flask-Login==0.5.0
Flask-SQLAlchemy==2.5.1
Flask-WTF==0.14.3
greenlet==1.1.0
gunicorn==20.1.0
idna==3.1
itsdangerous==2.0.0
Jinja2==3.0.0
MarkupSafe==2.0.0
Pillow==8.2.0
pycparser==2.20
six==1.16.0
SQLAlchemy==1.4.15
Werkzeug==2.0.0
WTForms==2.3.3

Procfile.txt

web: gunicorn app:run

run.py是我的文件名,如下:-

from gumshuda import app

if __name__ == "__main__":
    app.run(debug=True)

如有需要请询问更多信息。

我通过将我的文件从 run.py 重命名为 app.py 设法解决了这个问题 但根据评论中的@saransh singh 我们也可以通过更改 procfile 来解决它 来自 web: gunicorn app:runweb: gunicorn run:app