通过Boto.ses& amp; s连接到SES python错误

时间:2017-01-12 11:38:18

标签: python amazon-web-services virtualenv amazon-ses

很抱歉这个noobish问题但是我试图运行这段代码并且我不断收到下面发布的错误,我已经陷入困境,不知道该怎么做才能得到任何帮助。

import boto.ses

AWS_ACCESS_KEY = '.......'  
AWS_SECRET_KEY = '.......'

class Email(object):  
    def __init__(self, to, subject):
        self.to = to
        self.subject = subject
        self._html = None
        self._text = None
        self._format = 'html'

    def html(self, html):
        self._html = html

    def text(self, text):
        self._text = text

    def send(self, from_addr=None):
        body = self._html

        if isinstance(self.to, basestring):
            self.to = [self.to]
        if not from_addr:
            from_addr = 'abcd@abcd.com'
        if not self._html and not self._text:
            raise Exception('You must provide a text or html body.')
        if not self._html:
            self._format = 'text'
            body = self._text

        connection = boto.ses.connect_to_region(
            'us-west-2',
            aws_access_key_id=AWS_ACCESS_KEY, 
            aws_secret_access_key=AWS_SECRET_KEY
        )

        return connection.send_email(
            from_addr,
            self.subject,
            None,
            self.to,
            format=self._format,
            text_body=self._text,
            html_body=self._html
        )

email = Email(to='test@test.com', subject='OMG You are HTML Awesome')  
email.text('This is a text body. Foo bar.')  
email.html('<html><body>This is a text body. <strong>Foo bar.</strong>  
</body></html>')  # Optional  
email.send()

错误:

Traceback (most recent call last):
  File "email.py", line 1, in <module>
    import boto.ses
  File "/home/james/Documents/code/email/venv/local/lib/python2.7/site-packages/boto/ses/__init__.py", line 23, in <module>
    from boto.ses.connection import SESConnection
  File "/home/james/Documents/code/email/venv/local/lib/python2.7/site-packages/boto/ses/connection.py", line 26, in <module>
    from boto.connection import AWSAuthConnection
  File "/home/james/Documents/code/email/venv/local/lib/python2.7/site-packages/boto/connection.py", line 56, in <module>
    from boto import auth
  File "/home/james/Documents/code/email/venv/local/lib/python2.7/site-packages/boto/auth.py", line 34, in <module>
    import boto.utils
  File "/home/james/Documents/code/email/venv/local/lib/python2.7/site-packages/boto/utils.py", line 49, in <module>
    import smtplib
  File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
    import email.utils
  File "/home/james/Documents/code/email/src/email.py", line 52, in <module>
    email.send()
  File "/home/james/Documents/code/email/src/email.py", line 33, in send
    connection = boto.ses.connect_to_region(
AttributeError: 'module' object has no attribute 'ses'

1 个答案:

答案 0 :(得分:0)

我最终转移到sendgrid,因为这个项目更容易使用。