gpt4 book ai didi

python - 亚马逊 ses 获取错误结果 = conn.send_raw_email(msg.as_string(), AttributeError : 'NoneType' object has no attribute 'send_raw_email'

转载 作者:行者123 更新时间:2023-11-28 17:27:52 24 4
gpt4 key购买 nike

我正在尝试使用 ses 发送原始电子邮件并收到错误 result = 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()

最佳答案

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

关于python - 亚马逊 ses 获取错误结果 = conn.send_raw_email(msg.as_string(), AttributeError : 'NoneType' object has no attribute 'send_raw_email' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37174938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com