Heroku应用程序在尝试运行时不断崩溃怎么解决

我终于能够将我的应用程序部署到Heroku ..除非现在应用程序拒绝运行。 我的应用程序使用应用程序工厂,我在Windows上开发它。

我已经尝试创建一个runserver.py文件,该文件使用工厂的create_app()函数,然后在Procfile中将gunicorn指向它,就像web:gunicorn runserver:app但仍然没有。

这是我的项目布局:

adco_flask
|    .env | .gitignore | config.py | Procfile | requirements.txt | runserver.py | |___app | __init__.py | email.py | models.py | admin/ | auth/ | errors/ | static/ | tables/ | templates/

Within app's init, here is the code:

imports...

basedir = os.path.abspath(os.path.dirname(__file__)) dotenv_path = os.path.join(basedir, '.env') load_dotenv(dotenv_path) db = SQLAlchemy() login_manager = LoginManager() mail = Mail() bootstrap = Bootstrap() def create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True) if test_config is None: # load the instance config, if it exists, when not testing app.config.from_object(Config) else: # load the test config passed in app.config.from_object(test_config) db.init_app(app) migrate = Migrate(app, db) login_manager.init_app(app) mail.init_app(app) bootstrap.init_app(app) admin = Admin(app, name='ADCo', template_mode='bootstrap3', index_view=MyIndexView()) from app.auth import auth_bp app.register_blueprint(auth_bp) from app.tables import tables_bp app.register_blueprint(tables_bp) from app.errors import errors_bp app.register_blueprint(errors_bp) init_admin(admin) if not app.debug and not app.testing: if app.config['MAIL_SERVER']: auth = None if (app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']): auth = (app.config['MAIL_USERNAME'],app.config['MAIL_PASSWORD']) secure = None if app.config['MAIL_USE_TLS']: secure = () mail_handler = SMTPHandler( mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']), fromaddr='no-reply@{}'.format(app.config['MAIL_SERVER']), toaddrs=app.config['ADMINS'], subject='Application Error', credentials=auth, secure=secure ) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if app.config['LOG_TO_STDOUT']: stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) app.logger.addHandler(stream_handler) else: if not os.path.exists('logs'): os.mkdir('logs') file_handler = RotatingFileHandler('logs/microblog.log', maxBytes=10240, backupCount=10) file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s ' '[in %(pathname)s:%(lineno)d]')) file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) app.logger.info('Inventory startup') try: os.makedirs(app.instance_path) except OSError: pass return app def init_admin(admin): with warnings.catch_warnings(): from app.models import ( User, EstimatedCogs, BarrelCount ) warnings.filterwarnings('ignore','Fields missing from ruleset',UserWarning) admin.add_view(UserView(User, db.session)) admin.add_view(AdminView(EstimatedCogs, db.session)) admin.add_view(AdminView(BarrelCount, db.session))from flask_admin.menu importMenuLink admin.add_link(MenuLink(name='Inventory', url='/tables/index'))

Here is the config.py file:

import os
import app

basedir = os.path.abspath(os.path.dirname(__file__)) class Config(object): TESTING = False SECRET_KEY = os.environ.get('SECRET_KEY', None) SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_DATABASE_URI = (os.environ.get('DATABASE_URL') or 'sqlite:///' + os.path.join(basedir, 'app.db') ) MAIL_SERVER = 'smtp.gmail.com' MAIL_PORT = 587 MAIL_USERNAME = '[email protected]' MAIL_PASSWORD = 'password' MAIL_USE_TLS = True MAIL_USE_SSL = False ADMINS = ['[email protected]'] FLASK_ADMIN_SWATCH = 'yeti' LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT')

And the requirements.txt:

alembic==1.0.10 alpha-vantage==2.1.0 altgraph==0.16.1 appdirs==1.4.3 APScheduler==3.6.0 asn1crypto==0.24.0 atomicwrites==1.3.0 attrs==19.1.0 Babel==2.6.0 backcall==0.1.0 beautifulsoup4==4.7.1 bleach==3.0.2 blinker==1.4 certifi==2019.3.9 cffi==1.12.3 chardet==3.0.4 Click==7.0 colorama==0.4.1 coverage==4.5.3 cryptography==2.6.1 cycler==0.10.0 DateTime==4.3 decorator==4.3.0 defusedxml==0.5.0 Django==2.2 dominate==2.3.5 dropbox==9.3.0 entrypoints==0.2.3 et-xmlfile==1.0.1 Flask==1.0.3 flask-admin==1.5.3 Flask-Babel==0.12.2 Flask-Bootstrap==3.3.7.1 Flask-Login==0.4.1 Flask-Mail==0.9.1 Flask-Migrate==2.4.0 Flask-SQLAlchemy==2.4.0 Flask-Table==0.5.0 Flask-Testing==0.7.1 Flask-WTF==0.14.2 future==0.17.1 gunicorn==19.9.0 idna==2.8 ipykernel==5.1.0 ipython==7.0.1 ipython-genutils==0.2.0 ipywidgets==7.4.2 itsdangerous==1.1.0 jdcal==1.4 jedi==0.13.1 Jinja2==2.10.1 jsonschema==2.6.0 jupyter==1.0.0 jupyter-client==5.2.3 jupyter-console==6.0.0 jupyter-core==4.4.0 kiwisolver==1.0.1 lxml==4.3.3 macholib==1.11 Mako==1.0.10 MarkupSafe==1.1.1 matplotlib==3.0.3 mistune==0.8.4 more-itertools==7.0.0 mysql-connector==2.2.9 mysql-connector-python==8.0.15 nbconvert==5.4.0 nbformat==4.4.0 notebook==5.7.8 numpy==1.16.2 openpyxl==2.6.2 pandas==0.24.2 pandocfilters==1.4.2 parso==0.3.1 pefile==2018.8.8 pickleshare==0.7.5 Pillow==6.0.0 pluggy==0.9.0 prometheus-client==0.4.1 prompt-toolkit==2.0.6 protobuf==3.8.0 psycopg2==2.7.5 py==1.8.0 pyclean==1.0.0 pycparser==2.19 Pygments==2.2.0 PyInstaller==3.4 PyJWT==1.7.1 PyMySQL==0.9.3 pyparsing==2.4.0 pytest==4.4.1 pytest-cov==2.7.1 python-dateutil==2.8.0 python-docx==0.8.10 python-dotenv==0.10.2 python-editor==1.0.4 pytz==2019.1 pyzmq==17.1.2 qtconsole==4.4.2 requests==2.21.0Send2Trash==1.5.0 simplegeneric==0.8.1 six==1.12.0 soupsieve==1.9.1SQLAlchemy==1.3.3 sqlparse==0.3.0 terminado==0.8.1 testpath==0.4.2 tkcalendar==1.4.0 tornado==5.1.1 traitlets==4.3.2 tzlocal==1.5.1 urllib3==1.24.1 virtualenv==16.0.0 visitor==0.1.3 waitress==1.3.0 wcwidth==0.1.7 webencodings==0.5.1WebOb==1.8.5WebTest==2.0.33Werkzeug==0.15.4 widgetsnbextension==3.4.2WTForms==2.2.1 zope.interface==4.6.0

And the last two, the Procfile and runserver.py:

web: gunicorn runserver:app --log-file=-
from app import create_app
import config app = create_app(config.Config()) if __name__ == '__main__': app.run()

Everytime I run the application I get an error, which is these two errors repeating:

2019-06-27T02:37:49.887046+00:00 heroku[router]: at=error code=H10 desc="App cras hed" method=GET path="/" host=adco-inventory.herokuapp.com request_id=612e3edb-f8 22-43dc-9e86-095cd6e481fc fwd="45.47.140.132" dyno= connect= service= status=503 bytes= protocol=https 2019-06-27T02:37:50.312980+00:00 heroku[router]: at=error code=H10 desc="App cras hed" method=GET path="/favicon.ico" host=adco-inventory.herokuapp.com request_id= f34089fb-1bd5-4c22-be1d-fb340916fd49 fwd="45.47.140.132" dyno= connect= service= status=503 bytes= protocol=https


尝试重新创建Heroku服务器上发生的一切:

首先获得一个干净的虚拟环境(virtualenv venv,然后激活它)
pip install -r requirements.txt
使用gunicorn runserver:app自己运行procfile命令中的内容
此外,如果要查看更多日志,可以使用heroku logs --tail命令查看最新信息或转到Heroku上的项目页面,然后单击更多=>日志

猜你喜欢

转载自www.cnblogs.com/gamecenter/p/11096118.html