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
相关产品推荐
相关产品推荐

