Gunicorn 寻找已删除的模块;无法在 GCP 中运行 django 应用程序

gunicorn looking for deleted module; cannot run django application in GCP

提问人:nathan lachenmyer 提问时间:11/10/2023 更新时间:11/10/2023 访问量:121

问:

我有一个在 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.pyALLOWED_HOSTS = [*]

我已经从中删除了它,我卸载了它,我从我的模型中删除了对它的所有提及,我什至删除了我所有的迁移文件并重置了我的数据库,因为我在那里发现了这个模块的提及。我还能做些什么来摆脱这个错误?INSTALLED_APPSpip

python django google-cloud-platform google-app-engine

评论

0赞 NoCommandLine 11/10/2023
试试这个 - 再次将您的项目部署到新版本,然后选择不提升它的选项,即 然后转到并单击以在网络上打开此新版本,然后尝试再次打开您的页面,看看是否仍然收到错误。你也可以尝试在本地运行你的应用,但要用它来运行它,看看你是否收到同样的错误。gcloud app deploy --version=<new_version> --no-promoteconsole > App Engine > Versionsadmindev_appserver.py
0赞 nathan lachenmyer 11/11/2023
在 Web 上创建未升级的版本仍会导致相同的错误。我现在正在调查。dev_appserver.py
0赞 Roopa M 11/13/2023
您能否尝试以下线程中提到的步骤:thread1thread2,并检查您是否在 urls.py 中留下了任何引用
0赞 nathan lachenmyer 11/14/2023
@RoopaM 因此,我继续删除数据库(从头开始)并删除了所有迁移文件,并使用新的迁移重置它们。我还应该从 thread1 中尝试什么?
0赞 nathan lachenmyer 11/14/2023
@NoCommandLine我尝试使用,但显然它不适用于 Windows,所以我无法运行它:(虽然未升级的版本仍然不起作用。有什么建议吗?dev_apperserver.py

答: 暂无答案