Hello,
I’m being dramatic, but I have been looking everywhere. I also have to accept the possibility that the error could be in my code. I am attempting to use Sheety, Google Sheets, and Tequila to return IATA Codes for airports and put them into the sheet. The seemingly easiest part of simply copying/pasting the Tequila endpoint has been tough. When I run the script, I get 404, but my test for Tokyo does return the IATA Code TYO for Narita Airport. My code:
import requests
import os
# Make sure to import os for getenv
from dotenv import load_dotenv
load_dotenv()
TEQUILA_ENDPOINT = "https://tequila-api.kiwi.com"
TEQUILA_API_KEY = os.getenv("TEQUILA_API_KEY")
class FlightSearch:
def __init__(self):
self.tequila_endpoint = TEQUILA_ENDPOINT
self.api_key = TEQUILA_API_KEY
def get_iata_code(self, city_name):
location_endpoint = f"{TEQUILA_ENDPOINT}/locations/query"
headers = {"apikey": self.api_key}
query = {"term": city_name, "location_types": "city"}
response = requests.get(url=location_endpoint, params=query, headers=headers)
response.raise_for_status()
data = response.json()["locations"]
if data:
return data[0]["code"]
else:
return None
# Correct way to use the class and method
flight_search = FlightSearch()
test_city = "Tokyo"
iata_code = flight_search.get_iata_code(test_city)
print(f"The IATA code for {test_city} is: {iata_code}")
Any assistance would be appreciated.