2017-01-12 86 views
0

對不起noobish的問題,但我試圖運行這段代碼,我不斷收到下面發佈的錯誤,我卡住了,不知道如何去做任何事情幫助將不勝感激。鑑於通過Boto.ses&python連接到SES錯誤

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 = '[email protected]' 
     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='[email protected]', 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' 

回答

0

我結束了移動到sendgrid,因爲它是更容易爲這個項目工作。