Skip to content
Advertisement

Post files, but endpoint limits 50 posts per minute

Good afternoon, i’m completely new to coding and i need some help, i splitted a json file into ~2800 smaller json files and need to post to a certain endpoint, however the limit of the endpoint is ~50 files per minute.

Currently i have made this is python :

import requests

url = 'testtest'
headers = {'Authorization' : 'testtest', 'Accept' : '*/*', 'Content-Type' : 'application/json'}
r = requests.post(url, data=open('C:Accountmanagerjson1.json', 'rb'), headers=headers

The file names are json1 -> json2800

Currently it only posts 1 file, and i need to post all 2800 files with a limit of 50 per minute, is there someone who can help out :) ?

Advertisement

Answer

If your code is correct for 1 request, you should be able to do all of them like this :

import requests
from time import sleep

url = 'testtest'
headers = {'Authorization' : 'testtest', 'Accept' : '*/*', 'Content-Type' : 'application/json'}
for i in range(1, 2801): # for each file
    r = requests.post(url, data=open('C:Accountmanagerjson'+ i +'.json', 'rb'), headers=headers
    sleep(60/50) #for 50 requests per minute (60s)

I recommend you to replace 60/50 (last line) by something like 60/48 for example to be sure there is no problem due do lags

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement