简体   繁体   English

成功部署 Django API 到 Heroku 后应用程序错误

[英]Application Error after successfully deploying Django API to Heroku

I am making an api for my deep learning model.我正在为我的深度学习 model 制作 api。 The api is properly working on localhost. api 在本地主机上正常工作。 I tried to deploy it on Heroku.我尝试将它部署在 Heroku 上。 It is deployed but when I open the link it gives "Application error" like below image它已部署,但是当我打开链接时,它会给出“应用程序错误”,如下图所示

应用程序错误图像

Release log:发布日志:

2021-02-23 05:47:36.841582: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

Build log:构建日志:

-----> Building on the Heroku-20 stack
-----> Python app detected
 !     Python has released a security update! Please consider upgrading to python-3.7.10
       Learn More: https://devcenter.heroku.com/articles/python-runtimes
-----> Requirements file has been changed, clearing cached dependencies
-----> Installing python-3.7.8
-----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2
-----> Installing SQLite3
-----> Installing requirements with pip
       Collecting absl-py==0.11.0
         Downloading absl_py-0.11.0-py3-none-any.whl (127 kB)
       Collecting asgiref==3.3.1
         Downloading asgiref-3.3.1-py3-none-any.whl (19 kB)
       Collecting astunparse==1.6.3
         Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
       Collecting cachetools==4.2.1
         Downloading cachetools-4.2.1-py3-none-any.whl (12 kB)
       Collecting certifi==2020.12.5
         Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
       Collecting chardet==4.0.0
         Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
       Collecting dj-database-url==0.5.0
         Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
       Collecting Django==3.1.7
         Downloading Django-3.1.7-py3-none-any.whl (7.8 MB)
       Collecting djangorestframework==3.12.2
         Downloading djangorestframework-3.12.2-py3-none-any.whl (957 kB)
       Collecting flatbuffers==1.12
         Downloading flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
       Collecting gast==0.3.3
         Downloading gast-0.3.3-py2.py3-none-any.whl (9.7 kB)
       Collecting google-auth==1.27.0
         Downloading google_auth-1.27.0-py2.py3-none-any.whl (135 kB)
       Collecting google-auth-oauthlib==0.4.2
         Downloading google_auth_oauthlib-0.4.2-py2.py3-none-any.whl (18 kB)
       Collecting google-pasta==0.2.0
         Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
       Collecting grpcio==1.32.0
         Downloading grpcio-1.32.0-cp37-cp37m-manylinux2014_x86_64.whl (3.8 MB)
       Collecting gunicorn==20.0.4
         Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
       Collecting h5py==2.10.0
         Downloading h5py-2.10.0-cp37-cp37m-manylinux1_x86_64.whl (2.9 MB)
       Collecting idna==2.10
         Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
       Collecting Keras==2.4.3
         Downloading Keras-2.4.3-py2.py3-none-any.whl (36 kB)
       Collecting Keras-Preprocessing==1.1.2
         Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
       Collecting Markdown==3.3.3
         Downloading Markdown-3.3.3-py3-none-any.whl (96 kB)
       Collecting numpy==1.19.5
         Downloading numpy-1.19.5-cp37-cp37m-manylinux2010_x86_64.whl (14.8 MB)
       Collecting oauthlib==3.1.0
         Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
       Collecting opencv-python-headless==4.5.1.48
         Downloading opencv_python_headless-4.5.1.48-cp37-cp37m-manylinux2014_x86_64.whl (37.6 MB)
       Collecting opt-einsum==3.3.0
         Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
       Collecting Pillow==8.1.0
         Downloading Pillow-8.1.0-cp37-cp37m-manylinux1_x86_64.whl (2.2 MB)
       Collecting protobuf==3.15.1
         Downloading protobuf-3.15.1-cp37-cp37m-manylinux1_x86_64.whl (1.0 MB)
       Collecting psycopg2==2.8.6
         Downloading psycopg2-2.8.6.tar.gz (383 kB)
       Collecting pyasn1==0.4.8
         Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
       Collecting pyasn1-modules==0.2.8
         Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
       Collecting pytz==2021.1
         Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
       Collecting PyYAML==5.4.1
         Downloading PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl (636 kB)
       Collecting requests==2.25.1
         Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
       Collecting requests-oauthlib==1.3.0
         Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
       Collecting rsa==4.7.1
         Downloading rsa-4.7.1-py3-none-any.whl (36 kB)
       Collecting scipy==1.6.1
         Downloading scipy-1.6.1-cp37-cp37m-manylinux1_x86_64.whl (27.4 MB)
       Collecting six==1.15.0
         Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
       Collecting sqlparse==0.4.1
         Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
       Collecting tensorboard==2.4.1
         Downloading tensorboard-2.4.1-py3-none-any.whl (10.6 MB)
       Collecting tensorboard-plugin-wit==1.8.0
         Downloading tensorboard_plugin_wit-1.8.0-py3-none-any.whl (781 kB)
       Collecting tensorflow-cpu==2.4.1
         Downloading tensorflow_cpu-2.4.1-cp37-cp37m-manylinux2010_x86_64.whl (144.1 MB)
       Collecting tensorflow-estimator==2.4.0
         Downloading tensorflow_estimator-2.4.0-py2.py3-none-any.whl (462 kB)
       Collecting termcolor==1.1.0
         Downloading termcolor-1.1.0.tar.gz (3.9 kB)
       Collecting typing-extensions==3.7.4.3
         Downloading typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
       Collecting urllib3==1.26.3
         Downloading urllib3-1.26.3-py2.py3-none-any.whl (137 kB)
       Collecting Werkzeug==1.0.1
         Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
       Collecting whitenoise==5.2.0
         Downloading whitenoise-5.2.0-py2.py3-none-any.whl (19 kB)
       Collecting wrapt==1.12.1
         Downloading wrapt-1.12.1.tar.gz (27 kB)
       Collecting importlib-metadata; python_version < "3.8"
         Downloading importlib_metadata-3.4.0-py3-none-any.whl (10 kB)
       Collecting zipp>=0.5
         Downloading zipp-3.4.0-py3-none-any.whl (5.2 kB)
       Building wheels for collected packages: psycopg2, termcolor, wrapt
         Building wheel for psycopg2 (setup.py): started
         Building wheel for psycopg2 (setup.py): finished with status 'done'
         Created wheel for psycopg2: filename=psycopg2-2.8.6-cp37-cp37m-linux_x86_64.whl size=501629 sha256=d8931f1a9c43a4fda009cc1dd73998b6850c5cc8cd0b7262297232221c4cf24d
         Stored in directory: /tmp/pip-ephem-wheel-cache-f0cb0bho/wheels/25/78/75/9c0323f7e1fb42143cbd2439302beb7850a1034abb961cb281
         Building wheel for termcolor (setup.py): started
         Building wheel for termcolor (setup.py): finished with status 'done'
         Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4830 sha256=ba9857e440ee6b55aede8e87e2b021b3a0083e509349a35a86d794ec3e6a7d15
         Stored in directory: /tmp/pip-ephem-wheel-cache-f0cb0bho/wheels/3f/e3/ec/8a8336ff196023622fbcb36de0c5a5c218cbb24111d1d4c7f2
         Building wheel for wrapt (setup.py): started
         Building wheel for wrapt (setup.py): finished with status 'done'
         Created wheel for wrapt: filename=wrapt-1.12.1-cp37-cp37m-linux_x86_64.whl size=77160 sha256=d9035ca277353f42fff12ec8f3a38fea5ee667bac754005cdd9b12f528fd3847
         Stored in directory: /tmp/pip-ephem-wheel-cache-f0cb0bho/wheels/62/76/4c/aa25851149f3f6d9785f6c869387ad82b3fd37582fa8147ac6
       Successfully built psycopg2 termcolor wrapt
       ERROR: tensorflow-cpu 2.4.1 has requirement wheel~=0.35, but you'll have wheel 0.34.2 which is incompatible.
       Installing collected packages: six, absl-py, asgiref, astunparse, cachetools, certifi, chardet, dj-database-url, pytz, sqlparse, Django, djangorestframework, flatbuffers, gast, pyasn1, rsa, pyasn1-modules, google-auth, oauthlib, urllib3, idna, requests, requests-oauthlib, google-auth-oauthlib, google-pasta, grpcio, gunicorn, numpy, h5py, scipy, PyYAML, Keras, Keras-Preprocessing, typing-extensions, zipp, importlib-metadata, Markdown, opencv-python-headless, opt-einsum, Pillow, protobuf, psycopg2, Werkzeug, tensorboard-plugin-wit, tensorboard, tensorflow-estimator, wrapt, termcolor, tensorflow-cpu, whitenoise
       Successfully installed Django-3.1.7 Keras-2.4.3 Keras-Preprocessing-1.1.2 Markdown-3.3.3 Pillow-8.1.0 PyYAML-5.4.1 Werkzeug-1.0.1 absl-py-0.11.0 asgiref-3.3.1 astunparse-1.6.3 cachetools-4.2.1 certifi-2020.12.5 chardet-4.0.0 dj-database-url-0.5.0 djangorestframework-3.12.2 flatbuffers-1.12 gast-0.3.3 google-auth-1.27.0 google-auth-oauthlib-0.4.2 google-pasta-0.2.0 grpcio-1.32.0 gunicorn-20.0.4 h5py-2.10.0 idna-2.10 importlib-metadata-3.4.0 numpy-1.19.5 oauthlib-3.1.0 opencv-python-headless-4.5.1.48 opt-einsum-3.3.0 protobuf-3.15.1 psycopg2-2.8.6 pyasn1-0.4.8 pyasn1-modules-0.2.8 pytz-2021.1 requests-2.25.1 requests-oauthlib-1.3.0 rsa-4.7.1 scipy-1.6.1 six-1.15.0 sqlparse-0.4.1 tensorboard-2.4.1 tensorboard-plugin-wit-1.8.0 tensorflow-cpu-2.4.1 tensorflow-estimator-2.4.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.3 whitenoise-5.2.0 wrapt-1.12.1 zipp-3.4.0
-----> Discovering process types
       Procfile declares types -> release, web
-----> Compressing...
       Done: 305.3M
-----> Launching...
 !     Warning: Your slug size (305 MB) exceeds our soft limit (300 MB) which may affect boot time.
       Released v17
       https://damp-bayou-18222.herokuapp.com/ deployed to Heroku

Output of heroku logs --dyno router Output 的heroku logs --dyno router

2021-02-23T06:06:58.983807+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=damp-bayou-18222.herokuapp.com request_id=9d41bcd3-8555-4a03-a247-43ff200d5061 fwd="27.61.161.75" dyno= connect= service= status=503 bytes= protocol=http
2021-02-23T06:06:59.611890+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=damp-bayou-18222.herokuapp.com request_id=c4a3e114-c3af-4230-8081-63dd4401f113 fwd="27.61.161.75" dyno= connect= service= status=503 bytes= protocol

Procfile档案

release: python manage.py makemigrations --no-input
release: python manage.py migrate --no-input

web: gunicorn digitrec.wsgi

When I run the command heroku ps:sacle web=1 it gives the below output:当我运行命令heroku ps:sacle web=1时,它会给出以下 output:

Scaling dynos... done, now running web at 1:Free

I have tried many solutions from different answers of stackoverflow but nothing worked.我从stackoverflow的不同答案中尝试了许多解决方案,但没有任何效果。 Please help me out!!!请帮帮我!!!

Add log-file flag in web worker config在 web 工作人员配置中添加log-file标志

web: gunicorn digitrec.wsgi --log-file -
Warning: Your slug size (305 MB) exceeds our soft limit (300 MB) which may affect boot time.

Your app must boot within the time limit or it'll be killed您的应用程序必须在时间限制内启动,否则将被杀死

Using the release phase in the Procfile works, but the release phase isn't part of the build, meaning that the makemigrations command creates the files in an ephemeral file system, meaning your next push will create brand new migrations again, which can cause issues with the database.Procfile中使用release阶段有效,但发布阶段不是构建的一部分,这意味着makemigrations命令会在临时文件系统中创建文件,这意味着您的下一次推送将再次创建全新的迁移,这可能会导致问题与数据库。

Finally, if your app is serving any sort of static files, and is used in production, then the DEBUG setting being False will mean you'll have to run collectstatic (again, as part of the build and not release).最后,如果您的应用程序正在提供任何类型的 static 文件,并且在生产中使用,那么DEBUG设置为False将意味着您必须运行collectstatic (同样,作为构建的一部分而不是发布)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM