I am working with Twilio's API to return information about phone numbers. Some of the phone numbers are invalid and return an error such as
Traceback (most recent call last):
File "test_twilio.py", line 17, in <module>
number = client.lookups.phone_numbers("(4154) 693-
6078").fetch(type="carrier")
File "/Users/jawnsano/anaconda/lib/python2.7/site-
packages/twilio/rest/lookups/v1/phone_number.py", line 158, in fetch
params=params,
File "/Users/jawnsano/anaconda/lib/python2.7/site-
packages/twilio/base/version.py", line 82, in fetch
raise self.exception(method, uri, response, 'Unable to fetch
record')
twilio.base.exceptions.TwilioRestException:
HTTP Error Your request was:
GET /PhoneNumbers/(4154) 693-6078
Twilio returned the following information:
Unable to fetch record: The requested resource /PhoneNumbers/(4154)
693-6078 was not found
More information may be available here:
https://www.twilio.com/docs/errors/20404
If an error like the one shown above is returned, I want to print 'There is an error.' However, for my if statement, is there a way to make Python print that for when there is a traceback error/error in general? I think there is probably a better way than setting making it like
if returned_value = (super long error message):
etc...