当我运行它时,它在本地运行良好。我不确定为什么要得到@app.route('/', methods['GET'])
,因为我什至没有创建端点。任何帮助将非常感谢。
我的文件结构是
api/
app.py
Procfile
requirements.txt
runtime.txt
Procfile
web: gunicorn app:app
requirements.txt
bcrypt==3.1.7
cffi==1.13.2
Click==7.0
dominate==2.4.0
Flask==1.1.1
Flask-Cors==3.0.8
Flask-Login==0.4.1
Flask-SQLAlchemy==2.4.1
gunicorn
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
passlib==1.7.2
psycopg2==2.8.4
pycparser==2.19
six==1.13.0
SQLAlchemy==1.3.11
visitor==0.1.3
runtime.txt
python-3.6.8
app.py
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
import json
import bcrypt
from flask_cors import CORS
# To run the app just do flask run
app = Flask(__name__)
CORS(app)
# To create DB enter Python interperter
# from app import db
# db.create_all()
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# sqlite:///invest.db
app.config['SQLALCHEMY_DATABASE_URI'] = 'mydatabase'
app.config['SECRET_KEY'] = 'Thisissupposedtobesecret!'
db = SQLAlchemy(app)
# ENDPOINTS
...
我做了一个heroku日志-t这是结果:
2019-12-16T16:14:29.282866+00:00 app[web.1]:
2019-12-16T16:14:29.282869+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2019-12-16T16:14:29.282871+00:00 app[web.1]:
2019-12-16T16:14:29.282906+00:00 app[web.1]: Traceback (most recent call last):
2019-12-16T16:14:29.282945+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2019-12-16T16:14:29.283163+00:00 app[web.1]: sys.exit(run())
2019-12-16T16:14:29.283203+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2019-12-16T16:14:29.283424+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2019-12-16T16:14:29.283464+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 228, in run
2019-12-16T16:14:29.283776+00:00 app[web.1]: super().run()
2019-12-16T16:14:29.283817+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2019-12-16T16:14:29.284055+00:00 app[web.1]: Arbiter(self).run()
2019-12-16T16:14:29.284097+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 229, in run
2019-12-16T16:14:29.284410+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2019-12-16T16:14:29.284452+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
2019-12-16T16:14:29.284770+00:00 app[web.1]: self.stop()
2019-12-16T16:14:29.284777+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2019-12-16T16:14:29.285033+00:00 app[web.1]: time.sleep(0.1)
2019-12-16T16:14:29.285040+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2019-12-16T16:14:29.285236+00:00 app[web.1]: self.reap_workers()
2019-12-16T16:14:29.285242+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2019-12-16T16:14:29.285543+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2019-12-16T16:14:29.285575+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2019-12-16T16:14:29.381301+00:00 heroku[web.1]: State changed from up to crashed
2019-12-16T16:14:29.367172+00:00 heroku[web.1]: Process exited with status 1
2019-12-16T16:15:18.861149+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myapi request_id=37004995-0cae-433f-9ad9-43a0d772a806 fwd="73.94.198.186" dyno= connect= service= status=503 bytes= protocol=https
2019-12-16T16:15:19.311065+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myapi request_id=03434c6b-b8d7-4387-a688-ec09f164e988 fwd="73.94.198.186" dyno= connect= service= status=503 bytes= protocol=https
2019-12-16T16:18:13.000000+00:00 app[api]: Build started by user me
2019-12-16T16:19:02.256496+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-16T16:19:01.638136+00:00 app[api]: Release v4 created by user me
2019-12-16T16:19:01.638136+00:00 app[api]: Deploy 164d644c by user me
2019-12-16T16:19:05.955131+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2019-12-16T16:19:08.665289+00:00 app[web.1]: [2019-12-16 16:19:08 +0000] [4] [INFO] Starting gunicorn 20.0.4
2019-12-16T16:19:08.665843+00:00 app[web.1]: [2019-12-16 16:19:08 +0000] [4] [INFO] Listening at: http://0.0.0.0:9350 (4)
2019-12-16T16:19:08.665963+00:00 app[web.1]: [2019-12-16 16:19:08 +0000] [4] [INFO] Using worker: sync
2019-12-16T16:19:08.672673+00:00 app[web.1]: [2019-12-16 16:19:08 +0000] [10] [INFO] Booting worker with pid: 10
2019-12-16T16:19:08.713220+00:00 app[web.1]: [2019-12-16 16:19:08 +0000] [11] [INFO] Booting worker with pid: 11
2019-12-16T16:19:09.287774+00:00 heroku[web.1]: State changed from starting to up
2019-12-16T16:19:09.414113+00:00 app[web.1]: [2019-12-16 16:19:09 +0000] [11] [ERROR] Exception in worker process
2019-12-16T16:19:09.414143+00:00 app[web.1]: Traceback (most recent call last):
2019-12-16T16:19:09.414146+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-12-16T16:19:09.414148+00:00 app[web.1]: worker.init_process()
2019-12-16T16:19:09.414150+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2019-12-16T16:19:09.414152+00:00 app[web.1]: self.load_wsgi()
2019-12-16T16:19:09.414153+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2019-12-16T16:19:09.414155+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-12-16T16:19:09.414158+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-12-16T16:19:09.414160+00:00 app[web.1]: self.callable = self.load()
2019-12-16T16:19:09.414161+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-12-16T16:19:09.414163+00:00 app[web.1]: return self.load_wsgiapp()
2019-12-16T16:19:09.414165+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-12-16T16:19:09.414167+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-12-16T16:19:09.414169+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2019-12-16T16:19:09.414171+00:00 app[web.1]: mod = importlib.import_module(module)
2019-12-16T16:19:09.414173+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2019-12-16T16:19:09.414175+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-12-16T16:19:09.414177+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2019-12-16T16:19:09.414179+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2019-12-16T16:19:09.414180+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2019-12-16T16:19:09.414182+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2019-12-16T16:19:09.414184+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2019-12-16T16:19:09.414186+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2019-12-16T16:19:09.414188+00:00 app[web.1]: File "/app/app.py", line 61, in <module>
2019-12-16T16:19:09.414190+00:00 app[web.1]: @app.route('/', methods['GET'])
2019-12-16T16:19:09.414198+00:00 app[web.1]: NameError: name 'methods' is not defined
2019-12-16T16:19:09.414940+00:00 app[web.1]: [2019-12-16 16:19:09 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-12-16T16:19:09.474691+00:00 app[web.1]: [2019-12-16 16:19:09 +0000] [10] [ERROR] Exception in worker process
2019-12-16T16:19:09.474696+00:00 app[web.1]: Traceback (most recent call last):
2019-12-16T16:19:09.474699+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-12-16T16:19:09.474702+00:00 app[web.1]: worker.init_process()
2019-12-16T16:19:09.474704+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2019-12-16T16:19:09.474706+00:00 app[web.1]: self.load_wsgi()
2019-12-16T16:19:09.474708+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2019-12-16T16:19:09.474710+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-12-16T16:19:09.474712+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-12-16T16:19:09.474714+00:00 app[web.1]: self.callable = self.load()
2019-12-16T16:19:09.474716+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-12-16T16:19:09.474719+00:00 app[web.1]: return self.load_wsgiapp()
2019-12-16T16:19:09.474720+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-12-16T16:19:09.474722+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-12-16T16:19:09.474725+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2019-12-16T16:19:09.474726+00:00 app[web.1]: mod = importlib.import_module(module)
2019-12-16T16:19:09.474728+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2019-12-16T16:19:09.474731+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-12-16T16:19:09.474734+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2019-12-16T16:19:09.474736+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2019-12-16T16:19:09.474738+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2019-12-16T16:19:09.474740+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2019-12-16T16:19:09.474742+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2019-12-16T16:19:09.474744+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2019-12-16T16:19:09.474746+00:00 app[web.1]: File "/app/app.py", line 61, in <module>
2019-12-16T16:19:09.474748+00:00 app[web.1]: @app.route('/', methods['GET'])
2019-12-16T16:19:09.474755+00:00 app[web.1]: NameError: name 'methods' is not defined
2019-12-16T16:19:09.475586+00:00 app[web.1]: [2019-12-16 16:19:09 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-12-16T16:19:09.638346+00:00 app[web.1]: [2019-12-16 16:19:09 +0000] [4] [INFO] Shutting down: Master
2019-12-16T16:19:09.638436+00:00 app[web.1]: [2019-12-16 16:19:09 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-12-16T16:19:09.787420+00:00 heroku[web.1]: State changed from up to crashed
2019-12-16T16:19:09.766289+00:00 heroku[web.1]: Process exited with status 3
2019-12-16T16:19:11.000000+00:00 app[api]: Build succeeded
答案 0 :(得分:1)
log在app / app.py第61行上显示其内容,因此似乎是您的代码。您可以发布整个代码吗? 如果是这样,请
方法['GET']到方法= ['GET']
答案 1 :(得分:0)
默认情况下,API端点将是“ GET”方法,因此您可以将其写为@app.route('/', methods['GET'])
或@ app.route('/',Methods = ['GET' ])@app.route('/')
@ app.route('/',方法= [“ GET”]). That is, if we are mentioning the method then it would be like
@ app.route('/',方法= [“ POST”]){{1} }等。
示例:
or