Reputation: 167
I have a http get call in a self.method() which returns only [ ] in the response link in some cases. I want to use this output to handle exception in another method, like
if type(self.method()) is 'NoneType':
print "The object is not present"
else:
self.method2()
I am getting errors like
AttributeError: 'Response' object has no attribute 'URL'
How to catch the response output [] in if statement ?
Upvotes: 0
Views: 877
Reputation: 541
Assuming that self.method()
returns []
if the get
failed:
response = self.method()
if not response:
print 'response missing'
else:
do_things(reponse)
this snippet uses the fact that an implicit bool()
is cast on response
which evaluates to False
if the list is empty. it's basically a more readable version of: if response == []
Upvotes: 1