sendgrid / sendgrid-python

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

Able to send mail only one time, after it gives error 400 #903

Closed aworkaround closed 4 years ago

aworkaround commented 4 years ago

Issue Summary

I'm using this library to get users signup for my website, once they signup, they'll receive a mail. When I run the application, it works fine for first mail. But is not working for other mails if I signup again.

Code Snippet

def send_reset_email(user):
    token = 'xyz'
    mail.send_email(
    from_email='no-reply@demomail.in',
    to_email= user.email,
    subject='demo | Password reset link',
    text= f"""
Dear User,

Thanks to be part of us!

Please follow below link in order to reset your account password:

{url_for('some_function', token=token, _external=True)}

This link will be expired in 20 minutes. If you did not make this request then simply ignore this email and no changes will be made.
    """
    )

Exception/Log

python_http_client.exceptions.BadRequestsError: HTTP Error 400: Bad Request

Technical details:

childish-sambino commented 4 years ago

Recommend catching the error and logging the response body to see the error details. Example here: https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/error_handling.md