I'm trying to use the tequila API to retrieve flight prices but the server keeps returning this error:
Traceback (most recent call last):
File "C:\Users\Senna\Downloads\flight-deals-step-2-solution\flight-deals-step-2-solution\main.py", line 37, in <module>
flight = flight_search.check_flights(
File "C:\Users\Senna\Downloads\flight-deals-step-2-solution\flight-deals-step-2-solution\flight_search.py", line 54, in check_flights
response.raise_for_status()
File "C:\Users\Senna\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://tequila-api.kiwi.com/v2/search?fly_from=AMS&fly_to=CDG&date_from=15%2F08%2F2021&date_to=10%2F02%2F2022&nights_in_dst_from=7&nights_in_dst_to=28&flight_type=round&one_for_city=1&max_stopovers=0&curr=GBP
Process finished with exit code 1
this is my code: (method in class)
def check_flights(self, origin_city_code, destination_city_code, from_time, to_time):
headers = {"apikey": TEQUILA_API_KEY}
query = {
"fly_from": origin_city_code,
"fly_to": destination_city_code,
"date_from": from_time.strftime("%d/%m/%Y"),
"date_to": to_time.strftime("%d/%m/%Y"),
"nights_in_dst_from": 7,
"nights_in_dst_to": 28,
"flight_type": "round",
"one_for_city": 1,
"max_stopovers": 0,
"curr": "GBP"
}
response = requests.get(
url="https://tequila-api.kiwi.com/v2/search",
headers=headers,
params=query,
)
response.raise_for_status()
try:
data = response.json()["data"][0]
except IndexError:
print(f"No flights found for {destination_city_code}.")
return None
flight_data = FlightData(
price=data["price"],
origin_city=data["route"][0]["cityFrom"],
origin_airport=data["route"][0]["flyFrom"],
destination_city=data["route"][0]["cityTo"],
destination_airport=data["route"][0]["flyTo"],
out_date=data["route"][0]["local_departure"].split("T")[0],
return_date=data["route"][1]["local_departure"].split("T")[0]
)
print(f"{flight_data.destination_city}: £{flight_data.price}")
return flight_data