Python amazon ses getting error result=conn.send_raw_email(msg.as_string(),AttributeError:';非类型';对象没有属性';send#raw_email';

Python amazon ses getting error result=conn.send_raw_email(msg.as_string(),AttributeError:';非类型';对象没有属性';send#raw_email';,python,amazon-ses,Python,Amazon Ses,我正在尝试使用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_se

我正在尝试使用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
,得到的答复是你正试图访问非类型的.send_raw_email。因此,
conn==None
。你应该检查一下。如果你给出了无效的地区名称,for boto.ses.connect_to_地区会返回None。从这一点来看,你的问题是你的地区名称应该是使用小写而不是大写。

如果使用2.5版本下的python,则应检查env中的BOTO,因为aws SES目前不支持2.5版本下python的某些区域

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

$python
>>> from boto import ses
>>> ses.regions()
[RegionInfo:us-east-1] #this is region supported for python version