how to handle api response in python