简体   繁体   中英

i'm getting a 429 status when making api request call in django production on DO server but no such error occurs when running from local host

i have wrote this code as TOMTOM doesn't have python SDK for it services this function is called multiple times for route calculation when calling it on django production mode it throws the status of 429 after some 10 to 15 requests to api service but this doesnt happen on when i run it on local host in debug False even if the api calls are made more than 20 to 50 times.

def directions(request,geocodes):
    points = ''
    for p in geocodes:
        points += str(p['coordinates'][::-1]).replace('[','').replace(']','').replace(',','%2C').replace(' ','')
        points +='%3A'
    # try:
    req = f'https://api.tomtom.com/routing/1/calculateRoute/{points}/json?computeTravelTimeFor=all&routeType=fastest&avoid=unpavedRoads&travelMode=car&key={tomtom_api}'
    r =requests.get(f'https://api.tomtom.com/routing/1/calculateRoute/{points}/json?computeTravelTimeFor=all&routeType=fastest&avoid=unpavedRoads&travelMode=car&key={tomtom_api}')
    status = r.status_code
    print(r.status_code)
    if status == 200:
        results = r.json()
        return results
    elif status == 429:
        time.sleep(int(r.headers["Retry-After"]))
        r =requests.get(f'https://api.tomtom.com/routing/1/calculateRoute/{points}/json?computeTravelTimeFor=all&routeType=fastest&avoid=unpavedRoads&travelMode=car&key={tomtom_api}')
        results = r.json()
    return results

if i can get help on why this is happening it will be very much appreciated.thankyou

It sounds like you're not paying for these API services which in turn means you are limited to X amount of call's/day. Tomorrow your Call limit will reset and you will be able to start making requests from API again. It usually doesn't cost much depending on the API to generate unlimited calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM