【发布时间】:2020-01-17 12:55:05
【问题描述】:
我已经尝试了所有我能想到的方法,并且我浏览了 the AWS 和 RealPython 指南。老实说,我很茫然。
我开发了一个应用程序,它使用 pipenv 锁文件在我的本地机器上完美运行。因此,没有立即需要 requirements.txt,但是 EB 需要一个,因此,在 pipenv 环境打开的情况下,我运行了
pip freeze > requirements.txt
创建一个。它现在包含:
beautifulsoup4==4.6.0
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
cryptography==2.8
defusedxml==0.6.0
Django==2.1.1
django-allauth==0.40.0
django-modelcluster==4.4.1
django-taggit==0.24.0
django-treebeard==4.3.1
djangorestframework==3.11.0
draftjs-exporter==2.1.7
html5lib==1.0.1
idna==2.8
oauthlib==3.1.0
Pillow==5.4.1
pycparser==2.19
python3-openid==3.1.0
pytz==2019.3
requests==2.22.0
requests-oauthlib==1.2.0
six==1.14.0
sqlparse==0.3.0
Unidecode==1.1.1
urllib3==1.25.7
wagtail==2.5.2
webencodings==0.5.1
Willow==1.1
我不得不降级到 Django 2.1.1,因为有人说 2.2 的 EB 存在版本问题。我正在使用 python 3.6.8。
我收到一条错误消息,指出“WSGIPath 引用了一个不存在的文件”,我修复了这个问题
eb config
并搜索 wsgi 并将路径更改为
application_name/wsgi.py
现在,在运行时
eb create
eb deploy
我收到输出
Creating application version archive "app-60c1-200116_214620".
Uploading application_name/app-60c1-200116_214620.zip to S3. This may take a while.
Upload Complete.
2020-01-16 19:46:35 INFO Environment update is starting.
2020-01-16 19:46:38 INFO Deploying new version to instance(s).
2020-01-16 19:47:00 INFO New application version was deployed to running EC2 instances.
2020-01-16 19:47:00 INFO Environment update completed successfully.
我还在 base.py(settings.py 的 wagtail 版本)中将 url 添加到 ALLOWED_HOSTS 中。
该应用程序在本地运行,但是当我在服务器上运行它时,我收到 500 内部服务错误。以下是日志文件的部分内容:
-------------------------------------
/var/log/httpd/error_log
-------------------------------------
[Thu Jan 16 19:40:47.104485 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] mod_wsgi (pid=4284): Exception occurred processing WSGI script '/opt/python/current/app/educess/wsgi.py'.
[Thu Jan 16 19:40:47.104591 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] Traceback (most recent call last):
[Thu Jan 16 19:40:47.104624 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] File "/opt/python/current/app/educess/wsgi.py", line 16, in <module>
[Thu Jan 16 19:40:47.104629 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] application = get_wsgi_application()
[Thu Jan 16 19:40:47.104636 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Thu Jan 16 19:40:47.104640 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] django.setup(set_prefix=False)
[Thu Jan 16 19:40:47.104645 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
[Thu Jan 16 19:40:47.104649 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] apps.populate(settings.INSTALLED_APPS)
[Thu Jan 16 19:40:47.104655 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/apps/registry.py", line 83, in populate
[Thu Jan 16 19:40:47.104658 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] raise RuntimeError("populate() isn't reentrant")
[Thu Jan 16 19:40:47.104672 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] RuntimeError: populate() isn't reentrant
[Thu Jan 16 19:46:46.365964 2020] [mpm_prefork:notice] [pid 4279] AH00169: caught SIGTERM, shutting down
[Thu Jan 16 19:46:47.478417 2020] [suexec:notice] [pid 4716] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jan 16 19:46:47.494121 2020] [so:warn] [pid 4716] AH01574: module wsgi_module is already loaded, skipping
[Thu Jan 16 19:46:47.496176 2020] [http2:warn] [pid 4716] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Thu Jan 16 19:46:47.496186 2020] [http2:warn] [pid 4716] AH02951: mod_ssl does not seem to be enabled
[Thu Jan 16 19:46:47.496728 2020] [lbmethod_heartbeat:notice] [pid 4716] AH02282: No slotmem from mod_heartmonitor
[Thu Jan 16 19:46:47.496790 2020] [:warn] [pid 4716] mod_wsgi: Compiled for Python/3.6.2.
[Thu Jan 16 19:46:47.496794 2020] [:warn] [pid 4716] mod_wsgi: Runtime using Python/3.6.8.
[Thu Jan 16 19:46:47.498977 2020] [mpm_prefork:notice] [pid 4716] AH00163: Apache/2.4.41 (Amazon) mod_wsgi/3.5 Python/3.6.8 configured -- resuming normal operations
[Thu Jan 16 19:46:47.498995 2020] [core:notice] [pid 4716] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Thu Jan 16 19:46:50.530525 2020] [:error] [pid 4721] [remote 127.0.0.1:0] mod_wsgi (pid=4721): Target WSGI script '/opt/python/current/app/educess/wsgi.py' cannot be loaded as Python module.
[Thu Jan 16 19:46:50.530599 2020] [:error] [pid 4721] [remote 127.0.0.1:0] mod_wsgi (pid=4721): Exception occurred processing WSGI script '/opt/python/current/app/educess/wsgi.py'.
[Thu Jan 16 19:46:50.531288 2020] [:error] [pid 4721] [remote 127.0.0.1:0] Traceback (most recent call last):
[Thu Jan 16 19:46:50.531332 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "/opt/python/current/app/educess/wsgi.py", line 16, in <module>
[Thu Jan 16 19:46:50.531337 2020] [:error] [pid 4721] [remote 127.0.0.1:0] application = get_wsgi_application()
[Thu Jan 16 19:46:50.531344 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Thu Jan 16 19:46:50.531347 2020] [:error] [pid 4721] [remote 127.0.0.1:0] django.setup(set_prefix=False)
[Thu Jan 16 19:46:50.531353 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
[Thu Jan 16 19:46:50.531356 2020] [:error] [pid 4721] [remote 127.0.0.1:0] apps.populate(settings.INSTALLED_APPS)
[Thu Jan 16 19:46:50.531362 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
[Thu Jan 16 19:46:50.531365 2020] [:error] [pid 4721] [remote 127.0.0.1:0] app_config = AppConfig.create(entry)
[Thu Jan 16 19:46:50.531371 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
[Thu Jan 16 19:46:50.531374 2020] [:error] [pid 4721] [remote 127.0.0.1:0] module = import_module(entry)
[Thu Jan 16 19:46:50.531379 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "/opt/python/run/venv/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[Thu Jan 16 19:46:50.531382 2020] [:error] [pid 4721] [remote 127.0.0.1:0] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Jan 16 19:46:50.531388 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Thu Jan 16 19:46:50.531393 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Thu Jan 16 19:46:50.531399 2020] [:error] [pid 4721] [remote 127.0.0.1:0] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Thu Jan 16 19:46:50.531414 2020] [:error] [pid 4721] [remote 127.0.0.1:0] ModuleNotFoundError: No module named 'debug_toolbar'
请注意日志末尾的 ModuleNotFoundError。据我所知,我已经从应用程序中完全卸载了 debug_toolbar,但不知何故服务器仍然认为它存在。
任何可以为我指明正确方向的帮助将不胜感激。
编辑 1:无论 DEBUG 在 base.py 中设置为 True 还是 False,我仍然收到 500 内部服务器错误。
编辑 2:我认为问题与版本控制有关,但我不知道要更改什么来纠正它以及是否需要我重新创建整个项目。
谢谢,
约书亚。
【问题讨论】:
-
我建议您检查设置中的 INSTALLED_APPS 和 MIDDLEWARE,并确保您已删除 urls 文件中的任何导入(这是通常导入的位置)。希望它可以帮助你:)
-
是的,我检查了很多。非常令人困惑...:/,我想我可能会切换到 Heroku。
-
我只是建议你在 requirements.txt 文件中添加 'django-debug-toolbar==2.0' 依赖并继续调试。 PS:我真的很喜欢 Heroku :)
-
我刚刚创建了一个帐户,即使我已经给了亚马逊钱,我也会 100% 切换。相比之下,AWS 是一团糟。
标签: python django amazon-web-services amazon-elastic-beanstalk