0
申し訳ありませんが、このコードを実行しようとしましたが、以下のエラーが表示され続けています。助けに感謝します。与えられた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'