代码(python3.7)
import sendgrid
import os
from sendgrid.helpers.mail import Email, Mail, Content
sg = sendgrid.SendGridAPIClient(apikey=os.getenv('API_KEY'))
from_mail = Email('noreply@sendmail.com')
to_mail = Email('nobody@example.com')
subject = '测试一下sendgrid_API邮件发送'
content = Content('text/plain', '这是一封测试邮件,不要回复哦!')
mail = Mail(from_mail, to_mail, subject, content)
response = sg.client.mail.send.post(rerquest_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
错误提示(这段代码就是照着书抄下来的啊):
AttributeError: 'str' object has no attribute 'get'