HTTPError: Backend error. 400 Bad Request

Hi I am looping through 14,000 tickers in chunks of 100, retrieving 8 or so fields. The loop fails with error "400 Bad Request" most of the time. I have read various links on the topic, tried adding "set_timeout(500)" but still randomly fails. Is this because of the amount of RICS I am looping through? Is there a way this can be done without crashing? Below is the code.

for i in range(startpos,nosrnd+1,chuncks):
dfmcap, err = ek.get_data(riclist[i:i+chuncks],['TR.FreeFloatPct','TR.CompanyMarketCap','TR.IssueMarketCap','TR.ShareClass','TR.RegCountryCode','TR.CommonName','TR.CLOSEPRICE','TR.SharesOutstanding'],{'SDate':sd, 'EDate':sd, 'Curn':'USD'})
dfmcap1, err = ek.get_data(riclist[i:i+chuncks],['TR.CompanyMarketCap','TR.IssueMarketCap','TR.SharesOutstanding','TR.CLOSEPRICE'],{'SDate':setdate, 'EDate':setdate, 'Curn':'USD'})
print(i)
dfmcapsum = pd.concat([dfmcapsum,dfmcap], axis = 0)
dfmcapsum1 = pd.concat([dfmcapsum1,dfmcap1], axis = 0)

Best Answer

  • Jirapongse
    Jirapongse admin
    Answer ✓

    If it is a processing timeout at the server, set_timeout(500) will not help.

    When this happens, the API will throw an exception. Therefore, the application can catch it and re-request for several times, as mentioned in this question.