Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions use_cases/error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ Please see [here](https://github.com/sendgrid/python-http-client/blob/HEAD/pytho
There are also email specific exceptions located [here](../sendgrid/helpers/mail/exceptions.py)

```python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import (From, To, Subject, PlainTextContent, HtmlContent, Mail)
from python_http_client import exceptions
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import (From, To, Subject, PlainTextContent, HtmlContent, Mail)
from python_http_client import exceptions

sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
from_email = From("help@twilio.com")
to_email = To("ethomas@twilio.com")
subject = Subject("Sending with Twilio SendGrid is Fun")
plain_text_content = PlainTextContent("and easy to do anywhere, even with Python")
html_content = HtmlContent("<strong>and easy to do anywhere, even with Python</strong>")
message = Mail(from_email, to_email, subject, plain_text_content, html_content)
try:
response = sendgrid_client.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except exceptions.BadRequestsError as e:
print(e.body)
exit()
sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
from_email = From("help@twilio.com")
to_email = To("ethomas@twilio.com")
subject = Subject("Sending with Twilio SendGrid is Fun")
plain_text_content = PlainTextContent("and easy to do anywhere, even with Python")
html_content = HtmlContent("<strong>and easy to do anywhere, even with Python</strong>")
message = Mail(from_email, to_email, subject, plain_text_content, html_content)
try:
response = sendgrid_client.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except exceptions.BadRequestsError as e:
print(e.body)
exit()
```