如何修复AttributeError: module 'botocore.vendored.requests'无'exceptions'属性
解决AttributeError: module 'botocore.vendored.requests' has no attribute 'exceptions'
问题描述
发生异常:
AttributeError module 'botocore.vendored.requests' has no attribute 'exceptions' 文件 "/Users/shrikantpadhy/Desktop/SWA-ENGINE/gateai-preplanning-engine/runner/main.py",第8行,在<module>中 import boto3 AttributeError: module 'botocore.vendored.requests' has no attribute 'exceptions'
环境配置:
- python == 3.11.5
- boto3==1.34.140
- botocore==1.34.140
已尝试操作:重装boto3和botocore、更换Python版本,问题仍存在。
解决方法
1. 替换botocore.vendored.requests为标准requests库
botocore从较新版本开始,不再推荐使用内部封装的botocore.vendored.requests,且部分属性(如exceptions)已不再对外暴露。操作步骤:
- 安装标准requests库(未安装时执行):
pip install requests - 遍历代码中所有引用
botocore.vendored.requests的位置,替换为requests。示例:
原代码:
替换后:from botocore.vendored.requests.exceptions import RequestExceptionfrom requests.exceptions import RequestException
2. 锁定兼容版本(临时方案)
如果暂时无法修改代码,可以尝试降级到仍保留botocore.vendored.requests.exceptions的旧版本:
pip install boto3==1.29.0 botocore==1.32.0
3. 排查隐式依赖
部分第三方库可能会隐式引用botocore.vendored.requests,可通过以下命令排查:
pip freeze | xargs grep -l "botocore.vendored.requests"
找到对应依赖包后,优先更新到修复该问题的版本,或联系包作者处理。
内容的提问来源于stack exchange,提问作者Shrikant Padhy
相关产品推荐
相关产品推荐

