我已按代码要求创建了API密钥并将其添加到环境变量中。
以下是我正在使用的代码,并遵循此处提供的步骤。
以下是我正在使用的代码,并遵循此处提供的步骤。
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='from_email@example.com',
to_emails='to@example.com',
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
它抛出了这个错误:
Traceback (most recent call last):
File "sendgrid_email.py", line 18, in <module>
print(e.message)
AttributeError: "ForbiddenError" object has no attribute "message"
当打印出现异常并显示pylint警告时-
Instance of "Exception" has no "message" member
有没有关于我做错或者遗漏的想法?
此外,to_emails
只有一个电子邮件地址,我们如何附加多个收件人?