Closed
Description
Issue Summary
Here is a PR that implements the new error handling: sendgrid/python-http-client#17
Here is an example of usage:
import sendgrid
import os
from sendgrid.helpers.mail import *
from python_http_client import exceptions
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("dx@sendgrid.com")
to_email = Email("elmer.thomas@sendgrid.com")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
mail = Mail(from_email, subject, to_email, content)
try:
response = sg.client.mail.send.post(request_body=mail.get())
except exceptions.BadRequestsError as e:
print(e.body)
exit()
print(response.status_code)
print(response.body)
print(response.headers)
The examples should go under USE_CASES.md and be referenced from TROUBLESHOOTING.md under error handling.