JeanExtreme002 / FlightRadarAPI

:airplane: Unofficial SDK for FlightRadar24 for Python 3 and NodeJS
https://pypi.org/project/FlightRadarAPI/
MIT License
286 stars 62 forks source link

CloudflareError #53

Closed Sayechtan closed 9 months ago

Sayechtan commented 9 months ago

I'm collecting all arrival flights to certain airports. After a while I get this error: "CloudflareError: An unexpected error has occurred. Perhaps you are making too many calls?"

I can't replicate it. I also read the errors provided in this Code. But i wasn't able to solve it. I also set a sleep timer to 30 seconds.

Is there any possibility, to avoid this error?

  1. OS: Windows 11 home
  2. Python Version: 3.11.6
JeanExtreme002 commented 9 months ago

No. This error is raised by the server, because you are making too many requests. How long did your code got running?

Sayechtan commented 9 months ago

Sometimes up to 90 minutes sometimes after 10 minutes. I cant rebuild it.

JeanExtreme002 commented 9 months ago

But are you using try-except and trying the request again after some seconds? CloudflareError is very common to happen.

Sayechtan commented 9 months ago

I think it's because of this for-loop:

for page_number_last in range(-10, 0):
    airport_details = fr_api.get_airport_details(code=iata_code, page=page_number_last)
    found_flight_list = find_list_of_flights(airport_details)
    num_flights = len(found_flight_list)
    time.sleep(15)

    if num_flights == 100:
        page_number_last -= 1 
        break

I'm doing this, because I want the last page number with 100 flights, to get all flights from the last day.

JeanExtreme002 commented 9 months ago

Try something like this on your code:

time_for_waiting = 15
punishment = time_for_waiting

for page_number_last in range(-10, 0):
    try:
        airport_details = fr_api.get_airport_details(code=iata_code, page=page_number_last)
        found_flight_list = find_list_of_flights(airport_details)
    except:
        time.sleep(punishment)
        punishment *= 1.5  # Increase +50%
        continue

    punishment = time_for_waiting

    num_flights = len(found_flight_list)
    time.sleep(time_for_waiting)

    if num_flights == 100:
        page_number_last -= 1 
        break
Sayechtan commented 9 months ago

Thank you. I test it!

JeanExtreme002 commented 9 months ago

Did it work? I'm closing this issue for now. Open it again if you are still in trouble.

Sayechtan commented 9 months ago

It's working! Thank you