You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scrapy爬虫遇301重定向引发Decompressor无process属性错误求助

解决Scrapy Shell中301重定向引发的AttributeError: 'Decompressor' object has no attribute 'process'

快速临时解决:直接使用目标URL

301重定向是因为你请求的URL缺少www前缀和结尾斜杠,网站会自动重定向到标准地址。直接使用最终的目标URL可以跳过重定向,避免触发错误:

r = scrapy.Request('https://www.worldometers.info/world-population/population-by-country/')
fetch(r)

版本兼容修复(彻底解决)

这个错误通常是Scrapy与依赖库(如Twisted、cryptography)版本不兼容导致的,按以下步骤处理:

  • 升级Scrapy到最新稳定版:
    pip install --upgrade scrapy
    
  • 如果升级后仍报错,尝试指定兼容的Twisted版本:
    pip install twisted==22.10.0
    

临时禁用HTTP压缩中间件

如果以上方法无效,可以临时关闭HTTP压缩中间件,绕过解压过程的错误:

from scrapy.settings import Settings
# 禁用HTTP压缩中间件
custom_settings = Settings({'DOWNLOADER_MIDDLEWARES': {'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': None}})
# 使用自定义设置发起请求
fetch(scrapy.Request('http://worldometers.info/world-population/population-by-country', settings=custom_settings))

内容的提问来源于stack exchange,提问作者vju_8

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 01:09:56