amazon ses getting error result = conn.send_raw_email(msg.as_string(), AttributeError: 'NoneType' object has no attribute 'send_raw_email'

amazon ses getting error result = conn.send_raw_email(msg.as_string(), AttributeError: 'NoneType' object has no attribute 'send_raw_email'

我正在尝试使用 ses 发送原始电子邮件并收到错误结果 = conn.send_raw_email(msg.as_string(), AttributeError: 'NoneType' 对象没有属性 'send_raw_email',可以看看吗?非常感谢

import boto.ses
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart


def send_ses():
    to_emails = ['contact.ranvijay@gmail.com']
    COMMASPACE = ', '
    msg = MIMEMultipart()
    msg['Subject'] = 'test'
    msg['From'] = 'contact.ranvijay@gmail.com'
    msg['To'] = COMMASPACE.join(to_emails)
    # msg.attach(MIMEText(body))
    filename = '/Users/Mac/test/products/error_csv/price_upload_error_2016-05-10 19:50:06.868506.csv'

    attachment = open(filename, 'rb').read()
    part = MIMEApplication(attachment)
    part.add_header('Content-Disposition', 'attachment', filename='test.csv')
    msg.attach(part)

    try:
        conn = boto.ses.connect_to_region(
                'US-EAST-1',
                aws_access_key_id=AWS_ACCESS_KEY,
                aws_secret_access_key=AWS_SECRET_KEY
        )
    except Exception as e:
        return e.__str__()

    result = conn.send_raw_email(msg.as_string(),
                                 source=msg['From'],
                                 destinations=to_emails
                                 )

    return result if 'ErrorResponse' in result else ''

if __name__ == '__main__':
    send_ses()

您调用 conn.send_raw_email 并收到您正在尝试访问 NoneType 的 .send_raw_email 的响应。因此,conn == None。你应该检查一下。 docs for boto.ses.connect_to_region say it returns None if you give an invalid region name. From 看来你的问题是你的区域名称应该是小写而不是大写。

如果您使用 2.5 以下的 python,您应该检查您的 BOTO 环境,因为目前 2.5 版本以下 python 的 aws SES 不支持某些区域。

如果您使用 boto

,您可以在 shell 中查看您的区域支持
$python
>>> from boto import ses
>>> ses.regions()
[RegionInfo:us-east-1] #this is region supported for python version