0
call = 0
start_time = datetime.now()
file1 = open("data.txt","r")
for line in file1.readlines():
    if (datetime.now() - start_time).total_seconds() > 1 or call >= 90:
        # time.sleep(60 - (datetime.now() - start_time).total_seconds() + 60)
        time.sleep(10)
        start_time = datetime.now()
    line = line.strip()
    all_data = f"api/{line}"
    headers = {
    'accept': 'application/json',
    'X-CSRFToken': 'csrftoken',
    'Authorization': 'AuthToken'
    }
    try:
        r = requests.get(all_data, headers=headers)
        trading = r.json()
    except Exception as e:
        print(f'error with {line}')
    end_time = datetime.now()
    if trading:
        with open('/folder/'+line+'.json', 'w') as file_object:
            json.dump(trading, file_object)
        print("done with",line)
    call += 1

we need save api response on json file.

I have handle api call in time limit but it gives still Request was throttled error. I have 11000 something endpoint data. Rate Limit is In additional to the limits associated with your pricing plan, there is a throttle of 100 calls per second and 1,000 calls per minute. Exceeding this rate limit will result in reponse errors until the limit resets.

json file error response :

{
    "detail": "Request was throttled. Expected available in 1319 seconds."
}
coder
  • 23
  • 6
  • Use Proxy with request – Abhishek Nov 23 '21 at 16:41
  • Thanks @Abhishek, But I have no idea about proxy so please explain detail – coder Nov 24 '21 at 17:30
  • You can get free proxies from web, most of them wont last long cause they are free what can we expect ;) , other alternative is `tor`, it requires `requests[socks]` to install before using. You can use proxy in request like explained here https://stackoverflow.com/questions/8287628/proxies-with-python-requests-module – Abhishek Nov 24 '21 at 19:01

0 Answers0