sendgrid / sendgrid-python

The Official Twilio SendGrid Python API Library
https://sendgrid.com
MIT License
1.53k stars 711 forks source link

sandbox mode flag on sendgrid.helpers.mail.Mail TypeError: get expected at least 1 argument, got 0 #976

Closed adankro closed 3 years ago

adankro commented 3 years ago

Issue Summary

Trying to set the sandbox mode in an Email helper class, I get this exception: sendgrid/helpers/mail/mail.py in _get_or_none at line 128

this is how I'm trying to set the sandbox mode:

message.mail_settings = {'sandbox_mode':{'enable':is_sandbox}}

Code Snippet


        def send(self, recipients, subject, html, metadata, is_sandbox=False, bcc=None):
            message = sendgrid.helpers.mail.Mail(
            from_email=(self.sender_address, self.sender_name),
            to_emails=recipients,
            subject=subject,
            html_content=html
        )
        message.mail_settings = {'sandbox_mode':{'enable':is_sandbox}}
        message.reply_to = sendgrid.helpers.mail.ReplyTo(
            email=self.sender_address, name=self.sender_name, p=0
        )
        self.call_sendgrid(message)

Exception/Log

TypeError: get expected at least 1 argument, got 0
  File "rollfox/esp.py", line 356, in call_sendgrid
    client.send(message)
  File "sendgrid/sendgrid.py", line 95, in send
    response = self.client.mail.send.post(request_body=message.get())
  File "sendgrid/helpers/mail/mail.py", line 958, in get
    'mail_settings': self._get_or_none(self.mail_settings),
  File "sendgrid/helpers/mail/mail.py", line 128, in _get_or_none
    return from_obj.get() if from_obj is not None else None

Technical details:

adankro commented 3 years ago

solved using additional helper classes :


message.mail_settings = sendgrid.helpers.mail.mail_settings.MailSettings(
            sandbox_mode=sendgrid.helpers.mail.sandbox_mode.SandBoxMode(enable=is_sandbox))
´´´