【亲测有效】[twisted] CRITICAL: Unhandled error in Deferred 解决办法

本文分享了在使用Scrapy时遇到[twisted] CRITICAL: Unhandled error in Deferred错误的解决方法,亲测有效。问题源于在设置ITEM_PIPELINES时,由于将pipeline文件放入了pipelines包内,需要使用全限定类名,例如'tutorial.pipelines.jsonpipeline.jsonpipeline'。默认情况下,不需要包名,直接写类名即可。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[twisted] CRITICAL: Unhandled error in Deferred 解决办法【亲测有效】
SO答案:https://stackoverflow.com/questions/45314514/scrapy-importerror-no-module-named-pipelines

先说原因:
ITEM_PIPELINES = {
‘tutorial.pipelines.jsonpipeline’: 800, // 错误
‘tutorial.pipelines.jsonpipeline.jsonpipeline’: 800, // 正确,原因是scrapy的目录结构有特殊约定
}
这里把pipiline管道放到pipelines包去了,导致scrapy需要重复一次类名。
在这里插入图片描述----------------
默认pipelines.py包含所有的管道,如下:
ITEM_PIPELINES = {
‘tutorial.pipelines.jsonpipeline1’: 800,
‘tutorial.pipelines.jsonpipeline2’: 801,
}

在这里插入图片描述

Unhandled error in Deferred:
2022-04-30 23:19:28 [twisted] CRITICAL: Unhandled error in Deferred:

Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\envs\python383\lib\site-packages\scrapy\crawler.py", line 206, in crawl
    return self._crawl(crawler, *args, **kwargs)
  File "C:\ProgramData\Miniconda3\envs\python383\lib\site-pack
V2025-03-18 15:57:52 [scrapy.utils.log] INFO: Scrapy 2.11.2 started (bot: weibo) 2025-03-18 15:57:52 [scrapy.utils.log] INFO: Versions: lxml 5.3.1.0, libxml2 2.11.7, cssselect 1.2.0, parsel 1.9.1, w3lib 2.2.1, Twisted 24.11.0, Python 3.8.5 (t ags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)], pyOpenSSL 25.0.0 (OpenSSL 3.4.1 11 Feb 2025), cryptography 44.0.1, Platform Windows-10-10.0.22621-SP0 2025-03-18 15:57:52 [weibo_comment] INFO: Reading start URLs from redis key 'weibo_comment:start_urls' (batch size: 16, encoding: utf-8) 2025-03-18 15:57:52 [scrapy.addons] INFO: Enabled addons: [] 2025-03-18 15:57:52 [asyncio] DEBUG: Using selector: SelectSelector 2025-03-18 15:57:52 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.asyncioreactor.AsyncioSelectorReactor 2025-03-18 15:57:52 [scrapy.utils.log] DEBUG: Using asyncio event loop: asyncio.windows_events._WindowsSelectorEventLoop 2025-03-18 15:57:52 [scrapy.extensions.telnet] INFO: Telnet Password: ed3efe598fe58086 2025-03-18 15:57:52 [scrapy.middleware] INFO: Enabled extensions: ['scrapy.extensions.corestats.CoreStats', 'scrapy.extensions.telnet.TelnetConsole', 'scrapy.extensions.logstats.LogStats'] 2025-03-18 15:57:52 [scrapy.crawler] INFO: Overridden settings: {'BOT_NAME': 'weibo', 'DOWNLOAD_DELAY': 2, 'DUPEFILTER_CLASS': 'scrapy_redis.dupefilter.RFPDupeFilter', 'FEED_EXPORT_ENCODING': 'utf-8', 'NEWSPIDER_MODULE': 'weibo.spiders', 'REQUEST_FINGERPRINTER_IMPLEMENTATION': '2.7', 'ROBOTSTXT_OBEY': True, 'SCHEDULER': 'scrapy_redis.scheduler.Scheduler', 'SPIDER_MODULES': ['weibo.spiders'], 'TWISTED_REACTOR': 'twisted.internet.asyncioreactor.AsyncioSelectorReactor'} Unhandled error in Deferred: 2025-03-18 15:57:52 [twisted] CRITICAL: Unhandled error in Deferred: Traceback (most recent call last): File "e:\python\lib\site-packages\twisted\internet\defer.py", line 2017, in _inlineCallbacks result = context.run(gen.send, result) File "e:\python\lib\site-packages\scrapy\crawle
最新发布
03-19
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值