Amazon ses error error result = conn.send_raw_email(msg.as_string(),AttributeError:'NoneType'对象没有属性'send_raw_email'

问题描述 投票:3回答:2

[我正在尝试使用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 = ['[email protected]']
    COMMASPACE = ', '
    msg = MIMEMultipart()
    msg['Subject'] = 'test'
    msg['From'] = '[email protected]'
    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()

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

python amazon-ses
2个回答
2
投票

您致电conn.send_raw_email并收到响应,您正在尝试访问NoneType的.send_raw_email。因此,conn == None。您应该检查一下。 boto.ses.connect_to_region的docs表示如果输入无效的区域名称,则返回None。从this list of regions看来,您的问题是您的区域名称应小写而不是大写。


0
投票

如果您在2.5以下使用python,则应检查BOTO的环境,因为aws SES暂时不支持2.5以下版本的python。

如果使用boto,则可以在外壳中检查您的区域支持

© www.soinside.com 2019 - 2024. All rights reserved.