File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ This script demonstrates how to use the SparkPostAPIException class. This
3+ particular example will yield output similar to the following:
4+
5+ $ python send_transmission_exception.py
6+ 400
7+ {u'errors': [{u'message': u'Invalid domain', u'code': u'7001', u'description':
8+ u'Unconfigured Sending Domain <some-domain-you-havent-configured.com> '}]}
9+ ['Invalid domain Code: 7001 Description: Unconfigured Sending Domain
10+ <some-domain-you-havent-configured.com> \n ']
11+ """
12+
13+ from sparkpost import SparkPost
14+ from sparkpost .exceptions import SparkPostAPIException
15+
16+ sp = SparkPost ()
17+
18+ try :
19+ response = sp .transmissions .send (
20+ recipients = ['john.doe@example.com' ],
21+ text = 'Hello there' ,
22+ from_email = 'Testing <test@some-domain-you-havent-configured.com>' ,
23+ subject = 'Testing python-sparkpost exceptions'
24+ )
25+ except SparkPostAPIException as err :
26+ # http response status code
27+ print (err .status )
28+ # python requests library response object
29+ # http://docs.python-requests.org/en/master/api/#requests.Response
30+ print (err .response .json ())
31+ # list of formatted errors
32+ print (err .errors )
You can’t perform that action at this time.
0 commit comments