sendgrid / docs

Repository of Twilio SendGrid's product documentation.
https://sendgrid.com/docs
MIT License
235 stars 966 forks source link

Python QuickStart guide is out of date. #6481

Closed c-goldschmidt closed 3 years ago

c-goldschmidt commented 3 years ago

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)

Environment

Expected

Actual

Link to page: https://sendgrid.com/docs/for-developers/sending-email/quickstart-python/#complete-code-block