努力将Python应用程序部署到heroku,以应对gunicorn配置

如何解决努力将Python应用程序部署到heroku,以应对gunicorn配置

我继承了一个python django应用程序,并试图为其带来新的生命。它当前正在使用python 2.7和许多最终需要升级的旧软件包。但是升级之前的第一件事是我希望它在heroku上成功运行。到目前为止,我在本地运行良好,但是遇到了Heroku和Gunicorn问题。

这是我遇到的错误:

2020-09-10T03:48:27.212247+00:00 heroku[web.1]: Starting process with command `gunicorn spotlit_due_diligence.spotlit_due_diligence.wsgi:application`
2020-09-10T03:48:29.477479+00:00 heroku[web.1]: State changed from starting to up
2020-09-10T03:48:29.206728+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [4] [INFO] Starting gunicorn 19.10.0
2020-09-10T03:48:29.207159+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [4] [INFO] Listening at: http://0.0.0.0:45741 (4)
2020-09-10T03:48:29.207253+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [4] [INFO] Using worker: sync
2020-09-10T03:48:29.211268+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [11] [INFO] Booting worker with pid: 11
2020-09-10T03:48:29.250434+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [13] [INFO] Booting worker with pid: 13
2020-09-10T03:48:29.000000+00:00 app[api]: Build succeeded
2020-09-10T03:48:30.075238+00:00 app[web.1]: [2020-09-10 03:48:30 +0000] [11] [ERROR] Exception in worker process
2020-09-10T03:48:30.075250+00:00 app[web.1]: Traceback (most recent call last):
2020-09-10T03:48:30.075251+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",line 586,in spawn_worker
2020-09-10T03:48:30.075251+00:00 app[web.1]: worker.init_process()
2020-09-10T03:48:30.075251+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py",line 135,in init_process
2020-09-10T03:48:30.075252+00:00 app[web.1]: self.load_wsgi()
2020-09-10T03:48:30.075252+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py",line 144,in load_wsgi
2020-09-10T03:48:30.075252+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-09-10T03:48:30.075253+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py",line 67,in wsgi
2020-09-10T03:48:30.075253+00:00 app[web.1]: self.callable = self.load()
2020-09-10T03:48:30.075254+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py",line 52,in load
2020-09-10T03:48:30.075254+00:00 app[web.1]: return self.load_wsgiapp()
2020-09-10T03:48:30.075254+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py",line 41,in load_wsgiapp
2020-09-10T03:48:30.075255+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-09-10T03:48:30.075255+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py",line 350,in import_app
2020-09-10T03:48:30.075255+00:00 app[web.1]: __import__(module)
2020-09-10T03:48:30.075255+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/wsgi.py",line 33,in <module>
2020-09-10T03:48:30.075256+00:00 app[web.1]: application = get_wsgi_application()
2020-09-10T03:48:30.075256+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py",line 14,in get_wsgi_application
2020-09-10T03:48:30.075256+00:00 app[web.1]: django.setup()
2020-09-10T03:48:30.075256+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py",line 17,in setup
2020-09-10T03:48:30.075256+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG,settings.LOGGING)
2020-09-10T03:48:30.075257+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py",line 48,in __getattr__
2020-09-10T03:48:30.075257+00:00 app[web.1]: self._setup(name)
2020-09-10T03:48:30.075257+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py",line 44,in _setup
2020-09-10T03:48:30.075257+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2020-09-10T03:48:30.075257+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py",line 92,in __init__
2020-09-10T03:48:30.075258+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2020-09-10T03:48:30.075258+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py",line 37,in import_module
2020-09-10T03:48:30.075258+00:00 app[web.1]: __import__(name)
2020-09-10T03:48:30.075258+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/settings/powell.py",line 93,in <module>
2020-09-10T03:48:30.075259+00:00 app[web.1]: os.mkdir('encryption_keys')
2020-09-10T03:48:30.075259+00:00 app[web.1]: OSError: [Errno 17] File exists: 'encryption_keys'
2020-09-10T03:48:30.075406+00:00 app[web.1]: [2020-09-10 03:48:30 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-09-10T03:48:30.455830+00:00 app[web.1]: In file included from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h:7:0,2020-09-10T03:48:30.455837+00:00 app[web.1]: from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:34,2020-09-10T03:48:30.455838+00:00 app[web.1]: from /app/.heroku/python/include/python2.7/Python.h:19,2020-09-10T03:48:30.455839+00:00 app[web.1]: from .heroku/python/lib/python2.7/site-packages/magic/__pycache__/_cffi__x14a33f6ax54cebdac.c:2:
2020-09-10T03:48:30.455839+00:00 app[web.1]: /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:194:15: fatal error: limits.h: No such file or directory
2020-09-10T03:48:30.455840+00:00 app[web.1]: #include_next <limits.h>  /* recurse down to the real one */
2020-09-10T03:48:30.455841+00:00 app[web.1]: ^~~~~~~~~~
2020-09-10T03:48:30.455847+00:00 app[web.1]: compilation terminated.
2020-09-10T03:48:30.460417+00:00 app[web.1]: [2020-09-09 22:48:30 +0000] [13] [ERROR] Exception in worker process
2020-09-10T03:48:30.460418+00:00 app[web.1]: Traceback (most recent call last):
2020-09-10T03:48:30.460419+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",in spawn_worker
2020-09-10T03:48:30.460420+00:00 app[web.1]: worker.init_process()
2020-09-10T03:48:30.460420+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py",in init_process
2020-09-10T03:48:30.460420+00:00 app[web.1]: self.load_wsgi()
2020-09-10T03:48:30.460421+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py",in load_wsgi
2020-09-10T03:48:30.460421+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-09-10T03:48:30.460421+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py",in wsgi
2020-09-10T03:48:30.460422+00:00 app[web.1]: self.callable = self.load()
2020-09-10T03:48:30.460437+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py",in load
2020-09-10T03:48:30.460437+00:00 app[web.1]: return self.load_wsgiapp()
2020-09-10T03:48:30.460438+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py",in load_wsgiapp
2020-09-10T03:48:30.460438+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-09-10T03:48:30.460438+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py",in import_app
2020-09-10T03:48:30.460439+00:00 app[web.1]: __import__(module)
2020-09-10T03:48:30.460440+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/wsgi.py",in <module>
2020-09-10T03:48:30.460440+00:00 app[web.1]: application = get_wsgi_application()
2020-09-10T03:48:30.460440+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py",in get_wsgi_application
2020-09-10T03:48:30.460441+00:00 app[web.1]: django.setup()
2020-09-10T03:48:30.460441+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py",line 18,in setup
2020-09-10T03:48:30.460441+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2020-09-10T03:48:30.460442+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py",line 85,in populate
2020-09-10T03:48:30.460442+00:00 app[web.1]: app_config = AppConfig.create(entry)
2020-09-10T03:48:30.460442+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py",line 86,in create
2020-09-10T03:48:30.460443+00:00 app[web.1]: module = import_module(entry)
2020-09-10T03:48:30.460444+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py",in import_module
2020-09-10T03:48:30.460444+00:00 app[web.1]: __import__(name)
2020-09-10T03:48:30.460444+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/magic/__init__.py",line 1,in <module>
2020-09-10T03:48:30.460445+00:00 app[web.1]: from . import ffi
2020-09-10T03:48:30.460445+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/magic/ffi.py",line 27,in <module>
2020-09-10T03:48:30.460446+00:00 app[web.1]: ext_package="magic")
2020-09-10T03:48:30.460446+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/api.py",line 437,in verify
2020-09-10T03:48:30.460447+00:00 app[web.1]: lib = self.verifier.load_library()
2020-09-10T03:48:30.460447+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/verifier.py",line 113,in load_library
2020-09-10T03:48:30.460447+00:00 app[web.1]: self._compile_module()
2020-09-10T03:48:30.460448+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/verifier.py",line 210,in _compile_module
2020-09-10T03:48:30.460448+00:00 app[web.1]: outputfilename = ffiplatform.compile(tmpdir,self.get_extension())
2020-09-10T03:48:30.460448+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/ffiplatform.py",line 29,in compile
2020-09-10T03:48:30.460449+00:00 app[web.1]: outputfilename = _build(tmpdir,ext,compiler_verbose)
2020-09-10T03:48:30.460449+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/ffiplatform.py",line 62,in _build
2020-09-10T03:48:30.460450+00:00 app[web.1]: raise VerificationError('%s: %s' % (e.__class__.__name__,e))
2020-09-10T03:48:30.460450+00:00 app[web.1]: VerificationError: CompileError: command 'gcc' failed with exit status 1
2020-09-10T03:48:30.460742+00:00 app[web.1]: [2020-09-09 22:48:30 +0000] [13] [INFO] Worker exiting (pid: 13)
2020-09-10T03:48:30.512245+00:00 app[web.1]: Traceback (most recent call last):
2020-09-10T03:48:30.512247+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn",line 8,in <module>
2020-09-10T03:48:30.512302+00:00 app[web.1]: sys.exit(run())
2020-09-10T03:48:30.512325+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py",line 61,in run
2020-09-10T03:48:30.512364+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-09-10T03:48:30.512385+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py",line 223,in run
2020-09-10T03:48:30.512517+00:00 app[web.1]: super(Application,self).run()
2020-09-10T03:48:30.512521+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py",line 72,in run
2020-09-10T03:48:30.512562+00:00 app[web.1]: Arbiter(self).run()
2020-09-10T03:48:30.512565+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",line 232,in run
2020-09-10T03:48:30.512633+00:00 app[web.1]: self.halt(reason=inst.reason,exit_status=inst.exit_status)
2020-09-10T03:48:30.512637+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",line 345,in halt
2020-09-10T03:48:30.512724+00:00 app[web.1]: self.stop()
2020-09-10T03:48:30.512724+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",line 396,in stop
2020-09-10T03:48:30.512823+00:00 app[web.1]: time.sleep(0.1)
2020-09-10T03:48:30.512824+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",line 245,in handle_chld
2020-09-10T03:48:30.512888+00:00 app[web.1]: self.reap_workers()
2020-09-10T03:48:30.512891+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py",line 528,in reap_workers
2020-09-10T03:48:30.512992+00:00 app[web.1]: raise HaltServer(reason,self.WORKER_BOOT_ERROR)
2020-09-10T03:48:30.513066+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-09-10T03:48:30.580846+00:00 heroku[web.1]: Process exited with status 1
2020-09-10T03:48:30.625801+00:00 heroku[web.1]: State changed from up to crashed

通常我觉得我可以读懂错误并进行分类,但是我什至不知道从哪里开始。

这是我的procfile:

web: gunicorn spotlit_due_diligence.spotlit_due_diligence.wsgi:application

这是我的wsgi.py文件:

import os
from os.path import abspath,dirname
from sys import path

SITE_ROOT = dirname(dirname(abspath(__file__)))
path.append(SITE_ROOT)

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this,use
# mod_wsgi daemon mode with each site in its own daemon process,or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "jajaja.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE","settings.powell")
# from whitenoise.django import DjangoWhiteNoise
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server,if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

感谢您提供的任何指导!

解决方法

2020-09-10T03:48:30.075258+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/settings/powell.py",line 93,in <module>
2020-09-10T03:48:30.075259+00:00 app[web.1]: os.mkdir('encryption_keys')
2020-09-10T03:48:30.075259+00:00 app[web.1]: OSError: [Errno 17] File exists: 'encryption_keys'

独角兽开始了多名工人。在您的代码spotlit_due_diligence/spotlit_due_diligence/settings/powell.py第93行中,使用os.mkdir('encryption_keys')将文件夹创建为文件夹。
在第一个工作程序运行时运行良好,但在第二个工作程序运行时将抛出错误。

您将必须使代码更健壮并处理该异常。也不是每个项目都与gunicorn兼容。
您是否也在使用gunicorn在本地运行项目?您通常将其最后包裹在金枪鱼中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-