【问题标题】: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' object has no attribute 'send_raw_email'
【发布时间】:2020-01-29 15:43:25
【问题描述】:

我正在尝试使用 ses 发送原始电子邮件并收到错误结果 = conn.send_raw_email(msg.as_string(), AttributeError: 'NoneType' object has no attribute '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()

【问题讨论】:

    标签: python amazon-ses


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果您使用 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-20
        • 2021-05-28
        • 1970-01-01
        相关资源
        最近更新 更多