I am trying to deploy Scrapy with scrapyd-deploy
command and now it throws next error:
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"}
Line 24 and 25 in first_scrapy.settings are:
import django
django.setup()
And here is 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,
},
},
}
And BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
As I unserstand something is wrong in settings.LOGGING
but I can't get what. Can you help me?
This is not duplicate. That is the similar question, but I have different reasons of this error - I don't create.I have checked everything as it is shown on that question - and it works on local sever.
As
BASE_DIR
is declared and used from scrapy side, everything you set inside that settings file in the form of:would make reference to the path where scrapy works, shown in the error as:
So better define your own
LOG_DIR
in the settings file, not using the current path, in a know folder you can use:Or, set an environment variable in other file of your project (maybe in django) easily to grab from settings file:
Any other
.py
file:In
settings.py
file:Also you could log to
/tmp
using the relative path, as follows: