I am trying to fetch IATA codes from the Amadeus API and fill my Google Sheets’ column with that data (100 Days of Code: The Complete Python Pro Bootcamp, day 39)
My code is:
def get_destination_code(self, city_name):
IATA_ENDPOINT = "https://test.api.amadeus.com/v1/reference-data/locations/cities"
query = {
"keyword": city_name,
"max": "2",
"include": "AIRPORTS",
}
city_header = {
"Authorization": "Bearer " + self._token
}
response = requests.post(
url=IATA_ENDPOINT, headers=city_header, params=query)
print(f"Status code {response.status_code}. Airport IATA: {response.text}")
try:
code = response.json()["data"][0]['iataCode']
except IndexError:
print(f"IndexError: No airport code found for {city_name}.")
return "N/A"
except KeyError:
print(f"KeyError: No airport code found for {city_name}.")
return "Not Found"
return code
I am passing cities like Paris, Frankfurt, Tokyo, Hong Kong but I am getting this error:
Status code 500. Airport IATA:
{
"errors": [
"code": 38189,
"title": "Internal error",
"detail": "An internal error occurred, please contact your administrator",
"status": 500
}
]
}
What can I do?
I have changed the city names in uppercase, but it didn’t work.
2