Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python import boto3 error: cannot import name ClientError

I am trying to use AWS Simple Email Service with Python. I followed the Send an Email Using the AWS SDK for Python (Boto) sample code. The program cannot correctly import boto3.

When it tries to import boto3 for the first time, Python gives error ImportError: cannot import name ClientError.

If I try to import again, the error becomes ImportError: cannot import name certs.

I have also checked the installed boto3 version and it has same version as the sample code.

boto3 Version: 1.4.4
botocore Version: 1.5.95
like image 805
jiashenC Avatar asked Dec 03 '22 12:12

jiashenC


2 Answers

Your versions of boto3 and botocore are very dated. Install updated versions first. I would also update your installed version of the AWS CLI.

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

[UPDATE after comment]

After the updates, double check that you have at least the following versions when executing "aws --version":

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

Next try to send an email from the CLI. The following is a script for the Windows CMD Prompt. Modify with valid email addresses that are verified with SES. The same command modified a bit will work from Linux.

set [email protected]
set [email protected]
aws ses send-email --from %FROM% --destination ToAddresses=%TO% --message Subject={Data="Hello world
"},Body={Text={Data="Hello World"}}
like image 131
John Hanley Avatar answered Dec 25 '22 08:12

John Hanley


Finally, it turns out that this issue is related to name shadowing. Botocore actually has a module called email and I name my file also as email.py. As a result, botocore cannot import email module correctly.

like image 21
jiashenC Avatar answered Dec 25 '22 08:12

jiashenC