提问人:nathan lachenmyer 提问时间:11/10/2023 更新时间:11/10/2023 访问量:121
Gunicorn 寻找已删除的模块;无法在 GCP 中运行 django 应用程序
gunicorn looking for deleted module; cannot run django application in GCP
问:
我有一个在 GCP 上运行良好的 django 应用程序,我最近删除了一个依赖项:.我不需要这个功能,所以我从模型中删除了这些项目,迁移了数据库并卸载了模块。django-colorfields
现在,当我将项目部署到 GCP 时,我无法通过管理员登录页面。管理页面()显示得很好,但是当我输入用户名和密码并按回车键时,我收到HTTP 500内部服务器错误。https://myproject.com/admin
我检查了内部服务器日志,有许多 gunicorn 错误,但这个很突出:
2023-11-09 20:02:29.950
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
worker.init_process()
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/workers/gthread.py", line 95, in init_process
super().init_process()
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
2023-11-09 20:02:29.950
self.callable = self.load()
2023-11-09 20:02:29.950
^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2023-11-09 20:02:29.950
return self.load_wsgiapp()
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2023-11-09 20:02:29.950
return util.import_app(self.app_uri)
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/gunicorn/util.py", line 371, in import_app
2023-11-09 20:02:29.950
mod = importlib.import_module(module)
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.runtime/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
2023-11-09 20:02:29.950
return _bootstrap._gcd_import(name[level:], package, level)
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
2023-11-09 20:02:29.950
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
2023-11-09 20:02:29.950
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
2023-11-09 20:02:29.950
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
2023-11-09 20:02:29.950
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
2023-11-09 20:02:29.950
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2023-11-09 20:02:29.950
File "/srv/main.py", line 1, in <module>
2023-11-09 20:02:29.950
from polb_cms.wsgi import application
2023-11-09 20:02:29.950
File "/srv/polb_cms/wsgi.py", line 16, in <module>
2023-11-09 20:02:29.950
application = get_wsgi_application()
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2023-11-09 20:02:29.950
django.setup(set_prefix=False)
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
2023-11-09 20:02:29.950
apps.populate(settings.INSTALLED_APPS)
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/django/apps/registry.py", line 91, in populate
2023-11-09 20:02:29.950
app_config = AppConfig.create(entry)
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/django/apps/config.py", line 228, in create
2023-11-09 20:02:29.950
import_module(entry)
2023-11-09 20:02:29.950
File "/layers/google.python.runtime/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
2023-11-09 20:02:29.950
return _bootstrap._gcd_import(name[level:], package, level)
2023-11-09 20:02:29.950
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-09 20:02:29.950
ModuleNotFoundError: No module named 'colorfield'
2023-11-09 20:02:29.950
[2023-11-09 22:02:29 -0600] [18] [ERROR] Exception in worker process
最后一点-- --让我印象深刻。我已经删除了整个项目中的所有引用(我已经在我的整个项目中进行了查找+替换,但在任何地方都找不到它!),但是由于某种原因,我的GCP部署文件仍然认为它需要这个模块并且每次都有错误。ModuleNotFoundError: no module named 'colorfield'
django-colorfield
我的app.yaml文件非常简单:
# [START django_app]
# [START gaestd_py_django_app_yaml]
runtime: python311
env_variables:
# This setting is used in settings.py to configure your ALLOWED_HOSTS
APPENGINE_URL: https://my-project.uw.r.appspot.com/
GOOGLE_CLOUD_PROJECT: my-project
GS_BUCKET_NAME: "my-bucket"
handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
static_dir: static/
# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
script: auto
# [END gaestd_py_django_app_yaml]
# [END django_app]
我已经检查了其他常见问题 - 我有DEBUG=TRUE,以防万一。我仍然无法登录我的管理网站,这似乎是我目前拥有的最好的线索。settings.py
ALLOWED_HOSTS = [*]
我已经从中删除了它,我卸载了它,我从我的模型中删除了对它的所有提及,我什至删除了我所有的迁移文件并重置了我的数据库,因为我在那里发现了这个模块的提及。我还能做些什么来摆脱这个错误?INSTALLED_APPS
pip
答: 暂无答案
评论
gcloud app deploy --version=<new_version> --no-promote
console > App Engine > Versions
admin
dev_appserver.py
dev_appserver.py
urls.py
中留下了任何引用dev_apperserver.py