Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine the rate limit for requests

I have a question about rate limits. I take a data from the CSV and enter it into the query and the output is stored in a list. I get an error because I make too many requests at once. (I can only make 20 requests per second). How can I determine the rate limit?

import requests
import pandas as pd 

df = pd.read_csv("Data_1000.csv")
list = []



def requestSummonerData(summonerName, APIKey):

    URL = "https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/" + summonerName + "?api_key=" + APIKey
    response = requests.get(URL)
    return response.json()

def main():
    APIKey = (str)(input('Copy and paste your API Key here: '))

    for index, row in df.iterrows():
        summonerName = row['Player_Name']
        responseJSON  = requestSummonerData(summonerName, APIKey)
        ID = responseJSON ['accountId']
        ID = int(ID)
        list.insert(index,ID)

    df["accountId"]= list
like image 229
Sadiksk Avatar asked May 26 '18 11:05

Sadiksk


People also ask

How do you determine rate limit?

You may say rate limiting limits the number of operations performed within a given amount of time. Rate limiting can be implemented in tiers. E.g., a network request can be limited to 1 request per second, 4 requests per minute, 10 requests per 5 minutes.

What is request rate limit?

A rate limit is the number of API calls an app or user can make within a given time period. If this limit is exceeded or if CPU or total time limits are exceeded, the app or user may be throttled. API requests made by a throttled user or app will fail. All API requests are subject to rate limits.

How do I calculate my API rate limit?

Rate limits are calculated in Requests Per Second, or RPS. For example, let's say a developer only wants to allow a client to call the API a maximum of 10 times per minute. In this case the developer would apply a rate limit to their API expressed as “10 requests per 60 seconds”.

How can the request rate be defined?

The Request Rate is the maximum rate at which you can send API Requests to Scanova's API via your information system or mobile application. For example, if you are subscribed to the Starter Plan, you can send a maximum of 10 API Requests per second. Any additional API requests will be discarded by our API.


1 Answers

If you already know you can only make 20 requests per second, you just need to work out how long to wait between each request:

Divide 1 second by 20, which should give you 0.05. So you just need to sleep for 0.05 of a second between each request and you shouldn't hit the limit (maybe increase it a bit if you want to be safe).

import time at the top of your file and then time.sleep(0.05) inside of your for loop (you could also just do time.sleep(1/20))

like image 169
vimist Avatar answered Oct 02 '22 19:10

vimist