eventlet.monkey_patch()抛出异常:SECRET_KEY设置不能为空

时间:2017-09-17 14:06:09

标签: python django python-3.x eventlet

我有一个Django项目。我使用的包:Django 1.11,Eventlet 0.21.0。 Python版本是3.4.3。 有以下配置文件:

1)主项目的配置文件 settings.py 。导入其他两个配置文件之一的主要作用。

try:
    from .settings_local import *
except ImportError:
    from .conf.common import *

2) settings_local.py 。此文件的目的是从 common.py 导入所有设置,并覆盖文件正文中的那些(或添加一些新设置),例如用于测试目的:

from .conf.common import *
...

3) common.py 。包含所有配置设置的文件。

import eventlet
eventlet.monkey_patch(all=True, MySQLdb=True)
...

当我尝试检查配置时,出现以下错误:

./manage.py check

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/base.py", line 322, in execute
    saved_locale = translation.get_language()
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 195, in get_language
    return _trans.get_language()
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 59, in __getattr__
    if settings.USE_I18N:
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/vagrant/<project_name>/<project_name>/<project_name>/settings.py", line 2, in <module>
    from .settings_local import *
  File "/vagrant/<project_name>/<project_name>/<project_name>/settings_local.py", line 1, in <module>
    from .conf.common import *
  File "/vagrant/<project_name>/<project_name>/<project_name>/conf/common.py", line 3, in <module>
    eventlet.monkey_patch(all=True, MySQLdb=True)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/eventlet/patcher.py", line 254, in monkey_patch
    _green_existing_locks()
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/eventlet/patcher.py", line 345, in _green_existing_locks
    if isinstance(obj, rlock_type):
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/functional.py", line 238, in inner
    self._setup()
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 129, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

我发现异常最初发生在函数 _green_existing_locks()中的 /lib/python3.4/site-packages/eventlet/patcher.py 中,然后传播到 __ init.py __

有人能告诉我我做错了什么吗?

2 个答案:

答案 0 :(得分:2)

请注意设置和代码之间的区别。

ts-ebml

您不会将副作用生成代码放入设置中。根据您的版本的Django指南找到初始化代码的位置,并在那里放置# settings.py SECRET_KEY = 'abc...' DEBUG = True # just a list of constant definitions # your common.py eventlet.monkey_patch() # it's code that changes python environment # another bad example of settings.py with similar problem open('/tmp/flag-file-1', 'w') os.remove('/tmp/flag-file-2')

答案 1 :(得分:0)

  

django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置   不能为空。

以下错误表示未在设置中设置SECRET_KEY