Heroku-第一行出现code =“ H10”错误

时间:2020-04-29 22:06:36

标签: python flask heroku

因此,我尝试在线建立我的网站,并且它显示“构建成功”,但是当我尝试进入该网站时,出现此错误: enter image description here

所以我在终端中输入了命令,然后我的服务器出现了这个错误:

File "/app/Server.py", line 1, in <module>
import requests

requests包含在requirements.txt中,我不确定为什么会收到此错误 Procfile

web: gunicorn --bind 127.0.0.1:5000 Server:app

我正在使用python,flask,Server.py是文件名,app = Flask(__name__)

完整日志错误:

2020-04-29T22:00:54.375570+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-29T22:01:02.512425+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-29T22:01:02.199124+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-04-29T22:01:02.199914+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [4] [INFO] Listening at: http://127.0.0.1:5000 (4)
2020-04-29T22:01:02.200070+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [4] [INFO] Using worker: sync
2020-04-29T22:01:02.205899+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [9] [INFO] Booting worker with pid: 9
2020-04-29T22:01:02.231965+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [9] [ERROR] Exception in worker process
2020-04-29T22:01:02.231967+00:00 app[web.1]: Traceback (most recent call last):
2020-04-29T22:01:02.231990+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-29T22:01:02.231991+00:00 app[web.1]: worker.init_process()
2020-04-29T22:01:02.231991+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-29T22:01:02.231992+00:00 app[web.1]: self.load_wsgi()
2020-04-29T22:01:02.231992+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-29T22:01:02.231992+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-29T22:01:02.231993+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-29T22:01:02.231993+00:00 app[web.1]: self.callable = self.load()
2020-04-29T22:01:02.231993+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-29T22:01:02.231994+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-29T22:01:02.231994+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-29T22:01:02.231994+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-29T22:01:02.231995+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-29T22:01:02.231995+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-29T22:01:02.231996+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2020-04-29T22:01:02.231996+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-29T22:01:02.231997+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2020-04-29T22:01:02.231997+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2020-04-29T22:01:02.231997+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2020-04-29T22:01:02.231998+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2020-04-29T22:01:02.231998+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2020-04-29T22:01:02.231998+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-04-29T22:01:02.231999+00:00 app[web.1]: File "/app/Server.py", line 2, in <module>
2020-04-29T22:01:02.231999+00:00 app[web.1]: import requests
2020-04-29T22:01:02.231999+00:00 app[web.1]: ModuleNotFoundError: No module named 'requests'
2020-04-29T22:01:02.234426+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [9] [INFO] Worker exiting (pid: 9)
2020-04-29T22:01:02.276833+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [10] [INFO] Booting worker with pid: 10
2020-04-29T22:01:02.288853+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [10] [ERROR] Exception in worker process
2020-04-29T22:01:02.288854+00:00 app[web.1]: Traceback (most recent call last):
2020-04-29T22:01:02.288855+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-29T22:01:02.288856+00:00 app[web.1]: worker.init_process()
2020-04-29T22:01:02.288856+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-29T22:01:02.288856+00:00 app[web.1]: self.load_wsgi()
2020-04-29T22:01:02.288857+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-29T22:01:02.288857+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-29T22:01:02.288858+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-29T22:01:02.288858+00:00 app[web.1]: self.callable = self.load()
2020-04-29T22:01:02.288859+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-29T22:01:02.288859+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-29T22:01:02.288859+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-29T22:01:02.288860+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-29T22:01:02.288860+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-29T22:01:02.288861+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-29T22:01:02.288861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2020-04-29T22:01:02.288861+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-29T22:01:02.288862+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2020-04-29T22:01:02.288862+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2020-04-29T22:01:02.288863+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2020-04-29T22:01:02.288863+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2020-04-29T22:01:02.288863+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2020-04-29T22:01:02.288864+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-04-29T22:01:02.288864+00:00 app[web.1]: File "/app/Server.py", line 2, in <module>
2020-04-29T22:01:02.288864+00:00 app[web.1]: import requests
2020-04-29T22:01:02.288865+00:00 app[web.1]: ModuleNotFoundError: No module named 'requests'
2020-04-29T22:01:02.289094+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-04-29T22:01:02.400999+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [4] [INFO] Shutting down: Master
2020-04-29T22:01:02.401112+00:00 app[web.1]: [2020-04-29 22:01:02 +0000] [4] [INFO] Reason: Worker failed to boot.

enter image description here

1 个答案:

答案 0 :(得分:1)

所以第一个问题是我需要将所有模块安装到Pipfile(项目中的所有模块)。由于某种原因,如果您坚持要知道为什么它不起作用,请尝试阅读A question about it(可能需要重新修改),以确保我的requirements.txt没有通过。第二个问题就在我的头上:我将程序放在def main()中,因为@mechanical_meat说“应用程序必须在模块的顶层可用”,您不能这样做。