报错
Traceback (most recent call last):
File "E:\Python\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "E:\Python\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "E:\virtual_environment_list\Scrapy\Scripts\scrapy.exe\__main__.py", line 7, in <module>
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\cmdline.py", line 157, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\crawler.py", line 325, in __init__
super().__init__(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\crawler.py", line 197, in __init__
self.spider_loader = self._get_spider_loader(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\crawler.py", line 191, in _get_spider_loader
return loader_cls.from_settings(settings.frozencopy())
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\spiderloader.py", line 69, in from_settings
return cls(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\spiderloader.py", line 24, in __init__
self._load_all_spiders()
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\spiderloader.py", line 53, in _load_all_spiders
for module in walk_modules(name):
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\utils\misc.py", line 92, in walk_modules
submod = import_module(fullpath)
File "E:\Python\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "E:\project\pachong\qichezhijia\qichezhijia\spiders\qiche.py", line 13, in <module>
logging.config.fileConfig('logging.conf')
File "E:\Python\lib\logging\config.py", line 71, in fileConfig
formatters = _create_formatters(cp)
File "E:\Python\lib\logging\config.py", line 104, in _create_formatters
flist = cp["formatters"]["keys"]
File "E:\Python\lib\configparser.py", line 960, in __getitem__
raise KeyError(key)
KeyError: 'formatters'
(Scrapy) PS E:\project\pachong\qichezhijia\qichezhijia\spiders> scrapy runspider qiche.py
Traceback (most recent call last):
File "E:\Python\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "E:\Python\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "E:\virtual_environment_list\Scrapy\Scripts\scrapy.exe\__main__.py", line 7, in <module>
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\cmdline.py", line 157, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\crawler.py", line 325, in __init__
super().__init__(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\crawler.py", line 197, in __init__
self.spider_loader = self._get_spider_loader(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\crawler.py", line 191, in _get_spider_loader
return loader_cls.from_settings(settings.frozencopy())
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\spiderloader.py", line 69, in from_settings
return cls(settings)
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\spiderloader.py", line 24, in __init__
self._load_all_spiders()
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\spiderloader.py", line 53, in _load_all_spiders
for module in walk_modules(name):
File "E:\virtual_environment_list\Scrapy\lib\site-packages\scrapy\utils\misc.py", line 92, in walk_modules
submod = import_module(fullpath)
File "E:\Python\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "E:\project\pachong\qichezhijia\qichezhijia\spiders\qiche.py", line 13, in <module>
logging.config.fileConfig('logging.conf')
File "E:\Python\lib\logging\config.py", line 71, in fileConfig
formatters = _create_formatters(cp)
File "E:\Python\lib\logging\config.py", line 104, in _create_formatters
flist = cp["formatters"]["keys"]
File "E:\Python\lib\configparser.py", line 960, in __getitem__
raise KeyError(key)
KeyError: 'formatters'
原因:
找不到logging.conf
解决:
logging是从当前.py文件找的logging.conf
如
在qiche.py里用logging.conf
import logging.config
logging.config.fileConfig('../logging.conf')
logger = logging.getLogger()