Executing the code example from the Python QuickStart guide does not work.
Trace:
Traceback (most recent call last):
File "<proj_dir>/mailing.py", line 59, in <module>
mailer.send()
File "<proj_dir>/mailing.py", line 42, in send
mail_json = mail.get()
File "<lib_dir>\site-packages\sendgrid\helpers\mail\mail.py", line 969, in get
'personalizations': [p.get() for p in self.personalizations or []],
File "<lib_dir>\site-packages\sendgrid\helpers\mail\mail.py", line 969, in <listcomp>
'personalizations': [p.get() for p in self.personalizations or []],
File "<lib_dir>\site-packages\sendgrid\helpers\mail\personalization.py", line 235, in get
value = getattr(self, key)
File "<lib_dir>\site-packages\sendgrid\helpers\mail\personalization.py", line 51, in tos
return self._get_unique_recipients(self._tos)
File "<lib_dir>\site-packages\sendgrid\helpers\mail\personalization.py", line 35, in _get_unique_recipients
recipient_email = recipient['email'].lower() if isinstance(recipient, dict) else recipient.email.lower()
KeyError: 'email'
Code (from example, just customized content):
def send(self):
from_email = Email("<redacted: our service email>")
to_email = To("<redacted: my email address>")
subject = "Some subject"
content = Content("text/plain", "Todo: template here")
mail = Mail(from_email, to_email, subject, content)
mail_json = mail.get() # <- raises here
response = self.sendgrid.client.mail.send.post(request_body=mail_json)
Executing the code example from the Python QuickStart guide does not work.
Trace:
Code (from example, just customized content):
Environment
Expected
Actual
Link to page: https://sendgrid.com/docs/for-developers/sending-email/quickstart-python/#complete-code-block