Как добавить вложения в Sendgrid Django

Я пытаюсь понять, как добавить вложения в письмо, которое я отправляю через sendgrid. У меня есть файл .xlsx в той же директории, но он не прикрепляется. В настоящее время мой код выглядит следующим образом:

    with open(f'name-{filenumber}.xlsx', 'rb') as fd:
        encoded = base64.b64encode(fd.read())

    attachment = Attachment()

    attachment.content = (encoded, 'utf-8')


    attachment.filename = f'name-{filenumber}.xlsx'
    
    message = Mail(
    from_email='email.@email.com',
    to_emails= os.getenv("RECIPIENT_EMAIL"),
    subject='Sending with Twilio SendGrid is Fun',
    html_content='<strong>and easy to do anywhere, even with Python</strong>')
    message.add_attachment(attachment)

    try:
        sg = SendGridAPIClient('SENDGRID_API_KEY')
        response = sg.send(message)
        print(response.status_code)
        print(response.body)
        print(response.headers)
    except Exception as e:
        print(e.message)

Но я продолжаю получать эту ошибку AttributeError: 'BadRequestsError' object has no attribute 'message'

Вместе с этим:

python_http_client.exceptions.BadRequestsError: HTTP Error 400: Bad Request```
Вернуться на верх