Skip to main content
 首页 » 编程设计

Python导入boto3错误: cannot import name ClientError

2025年05月04日11luoye11

我正在尝试将 AWS Simple Email Service 与 Python 结合使用。我关注了Send an Email Using the AWS SDK for Python (Boto) sample code .程序无法正确导入boto3。

当它第一次尝试导入 boto3 时,Python 给出错误 ImportError: cannot import name ClientError。

如果我再次尝试导入,错误变为ImportError: cannot import name certs。

我还检查了安装的 boto3 版本,它与示例代码的版本相同。

boto3 Version: 1.4.4 
botocore Version: 1.5.95 

请您参考如下方法:

您的 boto3 和 botocore 版本非常过时。首先安装更新版本。我还会更新您安装的 AWS CLI 版本。

pip install boto3 --upgrade 
pip install awscli --upgrade 

[评论后更新]

更新后,在执行“aws --version”时仔细检查您是否至少有以下版本:

aws-cli/1.14.2 Python/2.7.9 Windows/8 botocore/1.8.6

接下来尝试从 CLI 发送电子邮件。以下是 Windows CMD 提示符的脚本。使用经过 SES 验证的有效电子邮件地址进行修改。稍作修改的同一命令将适用于 Linux。

set FROM=from@mydomain.com 
set TO=to@mydomain.com 
aws ses send-email --from %FROM% --destination ToAddresses=%TO% --message Subject={Data="Hello world 
"},Body={Text={Data="Hello World"}}