try: homework = response['homeworks'] except KeyError as error: blablabla..