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

Scrapy使用Fake User Agent报'type' object is not subscriptable错误的解决方法

解决Scrapy中fake-useragent的TypeError问题

错误原因

fake-useragent==2.0.0 采用了Python 3.9及以上版本才支持的list[BrowserUserAgentData]类型注解语法,而你的Python版本是3.8,不兼容该语法,因此触发TypeError: 'type' object is not subscriptable错误。

解决方案

  • 降级fake-useragent到兼容Python 3.8的版本,推荐安装1.4.0版本,执行以下命令:
    pip install fake-useragent==1.4.0 --force-reinstall
    
  • 若项目允许,可将Python版本升级至3.9及以上,直接适配新版本fake-useragent的语法要求。
  • 你同时安装了scrape-fake-useragent和fake-useragent,二者可能存在依赖冲突,建议只保留一个,例如卸载scrape-fake-useragent:
    pip uninstall scrape-fake-useragent
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 08:55:01