我正在使用 SendGrid 示例代码来确保我的令牌已准备就绪,但每次我尝试运行它时都会收到 RFC822 错误 我的示例代码:
import os
import sendgrid
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='[email protected]',
to_emails='[email protected]',
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
sg = sendgrid.SendGridAPIClient('some token')
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
我总是收到此错误:
ModuleNotFoundError: No module named 'rfc822'
During handling of the above exception, another exception occurred:
ImportError: cannot import name 'Mail' from partially initialized module 'sendgrid.helpers.mail' (most likely due to a circular import) (/home/userrrr/.local/lib/python3.8/site-packages/sendgrid/helpers/mail/__init__.py)
我正在使用 python3 和 pip3,也尝试过旧版本的 sendgrid,但没有希望,也在 Windows 和 Ubuntu 上尝试过
有什么想法吗? 谢谢你!
我通过将代码作为模块运行(例如
python -m myapp.sendgrid_script
)而不是使用 python sendgrid_script.py
执行脚本来修复此问题。