Django 1.10.3 Apache wsgi-ImportError:无法导入名称信号

Django 1.10.3 Apache wsgi-ImportError:无法导入名称信号

一夜之间,django 停止工作,可能是因为服务器上的自动软件包升级。其 wsgi 脚本现在无法在生产中加载,但运行开发服务器可以正常工作。什么可能导致以下错误?

mod_wsgi (pid=27634): Target WSGI script '/var/www/.../wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=27634): Exception occurred processing WSGI script '/var/www/.../wsgi.py'.
Traceback (most recent call last):
  File "/var/www/.../wsgi.py", line 13, in <module>
 from django.core.wsgi import get_wsgi_application
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 2, in <module>
 from django.core.handlers.wsgi import WSGIHandler
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 10, in <module>
 from django import http
  File "/usr/local/lib/python2.7/dist-packages/django/http/__init__.py", line 5, in <module>
 from django.http.response import (
  File "/usr/local/lib/python2.7/dist-packages/django/http/response.py", line 13, in <module>
 from django.core.serializers.json import DjangoJSONEncoder
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
 from django.core.serializers.base import SerializerDoesNotExist
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/base.py", line 4, in <module>
 from django.db import models
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/__init__.py", line 4, in <module>
 from django.db.models import signals  # NOQA
ImportError: cannot import name signals

wsgi.py文件如下:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "....settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

这在 24 小时前还有效,但现在已停止工作 - 我尝试过 django 1.10 和 1.10.3,但都出现了相同的症状。apache 2.4.18,python 2.7.12。

文件 /usr/local/lib/python2.7/dist-packages/django/db/models/signals.py 存在,因此原则上不应该有任何东西阻止导入。

答案1

事实证明有一个文件无法被网络服务器读取,并且错误日志中较早的一行标识了此文件。

IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/protobuf-3.1.0.post1-py2.7.egg/EGG-INFO/namespace_packages.txt'

我使用以下方法解决了该问题:

chmod -R o+r /usr/local/lib/python2.7/dist-packages

留下这个问题以防有人遇到同样的问题。

相关内容