I arrive to retrieve JSON from Yelp API. Problems arrive when I search for a town but that town is not in Yelp database. In this case I receive a response:
{
"error": {
"code": "LOCATION_NOT_FOUND",
"description": "Could not execute search, try specifying a more exact location."
}
}
As I'm searching in bulk I would like to write a statement that says that if
"LOCATION_NOT_FOUND" is inside my JSON response, do nothing and pass to the next town.
I need something like this:
if response_data['error']['code'] == 'LOCATION_NOT_FOUND':
pass
else:
but is not working because it says:
if response_data['error']['code'] == 'LOCATION_NOT_FOUND':
KeyError: 'error'
this because error is not always there but just when there is no town