It worked for me when I swapped
for ancestors = taxon_info.get("results", {})[0].get("ancestors", []) (and also added a time.sleep() into get_taxon_info, and also removed the encoding from to_excel)
ancestors = taxon_info.get("results", {})[0].get("ancestors", [])