我正在尝试在 Elastic Beanstalk 上部署一个 hello-world 类型的应用程序。几乎一切似乎都在工作,安装包等,直到 mod_wsgi 尝试从 wsgi.py 检索“应用程序”对象。此时,日志中会出现以下内容(每个不成功的 HTTP 请求在日志中出现一次):
mod_wsgi (pid=6114): Target WSGI script '/opt/python/current/app/myapp/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=6114): Exception occurred processing WSGI script '/opt/python/current/app/myapp/wsgi.py'.
Traceback (most recent call last):
File "/opt/python/current/app/caserails/wsgi.py", line 20, in <module>
application = get_wsgi_application()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/opt/python/run/venv/lib/python2.7/site-packages/django/utils/log.py", line 16, in <module>
from logging import NullHandler # NOQA
ImportError: cannot import name NullHandler
最佳答案
NullHandler
仅适用于 Python 2.7+ 版本。您可以在 ImportError
上自己创建 NullHandler
:
import logging
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
logging.getLogger(__name__).addHandler(NullHandler())
关于 logging.NullHandler
的更多信息:https://docs.python.org/3/library/logging.handlers.html#logging.NullHandler .
关于python - 导入错误 : cannot import name NullHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26939308/