我正在尝试使用scrapyd-deploy
命令部署Scrapy,现在它会抛出下一个错误:
Packing version 1526919848
Deploying to project "first_scrapy" in http://my_ip:6800/addversion.json
Server response (200):
{"node_name": "polo", "message": "Traceback (most recent call last):\n File \"/usr/lib/python3.5/logging/config.py\", line 558, in configure\n handler = self.configure_handler(handlers[name])\n
File \"/usr/lib/python3.5/logging/config.py\", line 731, in configure_handler\n result = factory(**kwargs)\n File \"/usr/lib/python3.5/logging/__init__.py\", line 1008, in __init__\n StreamHandler.__init__(self, self._open())\n
File \"/usr/lib/python3.5/logging/__init__.py\", line 1037, in _open\n return open(self.baseFilename, self.mode, encoding=self.encoding)\nNotADirectoryError: [Errno 20] Not a directory: '/tmp/first_scrapy-1526919848-13w8cqlm.egg/debug.log'\n\nDuring handling of the above exception, another exception occurred:\n\n
Traceback (most recent call last):\n File \"/usr/lib/python3.5/runpy.py\", line 184, in _run_module_as_main\n \"__main__\", mod_spec)\n File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n
File \"/home/chiefir/lib/python3.5/site-packages/scrapyd/runner.py\", line 40, in <module>\n main()\n File \"/home/chiefir/lib/python3.5/site-packages/scrapyd/runner.py\", line 37, in main\n execute()\n File \"/home/chiefir/lib/python3.5/site-packages/scrapy/cmdline.py\", line 109, in execute\n settings = get_project_settings()\n
File \"/home/chiefir/lib/python3.5/site-packages/scrapy/utils/project.py\", line 68, in get_project_settings\n settings.setmodule(settings_module_path, priority='project')\n File \"/home/chiefir/lib/python3.5/site-packages/scrapy/settings/__init__.py\", line 292, in setmodule\n module = import_module(module)\n
File \"/home/chiefir/lib/python3.5/importlib/__init__.py\", line 126, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n
File \"<frozen importlib._bootstrap>\", line 986, in _gcd_import\n
File \"<frozen importlib._bootstrap>\", line 969, in _find_and_load\n
File \"<frozen importlib._bootstrap>\", line 958, in _find_and_load_unlocked\n
File \"<frozen importlib._bootstrap>\", line 664, in _load_unlocked\n
File \"<frozen importlib._bootstrap>\", line 634, in _load_backward_compatible\n
File \"/tmp/first_scrapy-1526919848-13w8cqlm.egg/first_scrapy/settings.py\", line 25, in <module>\n File \"/home/chiefir/lib/python3.5/site-packages/django/__init__.py\", line 22, in setup\n configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\n
File \"/home/chiefir/lib/python3.5/site-packages/django/utils/log.py\", line 75, in configure_logging\n logging_config_func(logging_settings)\n File \"/usr/lib/python3.5/logging/config.py\", line 795, in dictConfig\n dictConfigClass(config).configure()\n
File \"/usr/lib/python3.5/logging/config.py\", line 566, in configure\n '%r: %s' % (name, e))\n
ValueError: Unable to configure handler 'file': [Errno 20] Not a directory: '/tmp/first_scrapy-1526919848-13w8cqlm.egg/debug.log'\n",
"status": "error"}
first_scrapy.settings中的第24行和第25行是:
import django
django.setup()
这是my_project.settings.LOGGING
:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'WARNING',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'debug.log'),
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'WARNING',
'propagate': True,
},
},
}
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
因为我在settings.LOGGING
中遗漏了一些错误,但我无法得到什么。你能帮帮我吗?
这不重复。这是类似的问题,但我有这个错误的不同原因 - 我没有创建。我检查了该问题上显示的所有内容 - 它可以在本地服务器上运行。
答案 0 :(得分:1)
从scrapy方面声明并使用BASE_DIR
时,您在该设置文件中设置的所有内容都采用以下形式:
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
会引用scrapy的工作路径,如错误所示:
/tmp/first_scrapy-1526919848-13w8cqlm.egg
最好在设置文件中定义自己的LOG_DIR
,而不是使用当前路径,在您可以使用的已知文件夹中:
LOG_DIR = '/path/to/logs/'
'filename': os.path.join(LOG_DIR, 'debug.log')
或者,在项目的其他文件中设置一个环境变量(可能在django中),可以轻松地从设置文件中获取:
任何其他.py
文件:
import os
os.environ['LOG_DIR'] = '/path/to/log/'
在settings.py
档案中:
LOG_DIR=os.environ['LOG_DIR']
'filename': os.path.join(LOG_DIR, 'debug.log')
您可以使用相对路径登录/tmp
,如下所示:
'filename': os.path.join(BASE_DIR, '..', 'debug.log')