部署Scrapy时发生ValueError [英] ValueError while deploying Scrapy

查看:61
本文介绍了部署Scrapy时发生ValueError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 scrapyd-deploy 命令部署Scrapy,现在它会引发下一个错误:

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"}

first_scrapy中的第24行和第25行。设置为:

Line 24 and 25 in first_scrapy.settings are:

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 中有什么问题,但是我可以不能得到什么。您能帮我吗?

这不是重复的。这是类似的问题,但是我有不同的原因导致此错误-我没有创建。我已经检查了该问题上显示的所有内容-并且可以在本地服务器上使用。

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.

推荐答案

由于 BASE_DIR 是从草率方面声明和使用的,因此您在该设置文件中设置的所有内容的形式为:

As BASE_DIR is declared and used from scrapy side, everything you set inside that settings file in the form of:

os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

将引用scrapy工作的路径,在错误中显示为:

would make reference to the path where scrapy works, shown in the error as:

/tmp/first_scrapy-1526919848-13w8cqlm.egg

因此最好在设置文件中定义自己的 LOG_DIR ,而不使用当前路径,在一个已知文件夹中,您可以使用:

So better define your own LOG_DIR in the settings file, not using the current path, in a know folder you can use:

LOG_DIR = '/path/to/logs/'

'filename': os.path.join(LOG_DIR, 'debug.log')

或者在项目的其他文件中设置环境变量(也许在Django中)轻松从设置文件中获取:

Or, set an environment variable in other file of your project (maybe in django) easily to grab from settings file:

任何其他 .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 使用相对路径,如下所示:

Also you could log to /tmp using the relative path, as follows:

'filename': os.path.join(BASE_DIR, '..', 'debug.log')

这篇关于部署Scrapy时发生ValueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆