-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rich Leland
committed
Feb 1, 2017
1 parent
c874555
commit 2527735
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
This script demonstrates how to use the SparkPostAPIException class. This | ||
particular example will yield output similar to the following: | ||
$ python send_transmission_exception.py | ||
400 | ||
{u'errors': [{u'message': u'Invalid domain', u'code': u'7001', u'description': | ||
u'Unconfigured Sending Domain <some-domain-you-havent-configured.com> '}]} | ||
['Invalid domain Code: 7001 Description: Unconfigured Sending Domain | ||
<some-domain-you-havent-configured.com> \n'] | ||
""" | ||
|
||
from sparkpost import SparkPost | ||
from sparkpost.exceptions import SparkPostAPIException | ||
|
||
sp = SparkPost() | ||
|
||
try: | ||
response = sp.transmissions.send( | ||
recipients=['john.doe@example.com'], | ||
text='Hello there', | ||
from_email='Testing <test@some-domain-you-havent-configured.com>', | ||
subject='Testing python-sparkpost exceptions' | ||
) | ||
except SparkPostAPIException as err: | ||
# http response status code | ||
print(err.status) | ||
# python requests library response object | ||
# http://docs.python-requests.org/en/master/api/#requests.Response | ||
print(err.response.json()) | ||
# list of formatted errors | ||
print(err.errors) |