I want to send a bulk of requests using requests.futures library in python.
The problem is some of the requests are getting Server Error in API response with 200 ok status code.
I need to implement a fallback mechanism to resend the failed requests and get the actual data from server.
This is what I have implemented.
- Code to send bulk data and getting bulk response using futures library
def sendBulkRequests(requestURLs):
# this would send data to server
return responseList
- Validate Response
requestURLsToRetry = []
for i in range(len(responseList)):
if 'sometext' not in responseList[i].text:
requestURLsToRetry.append(requestURLs[i])
Now I need to resend requestURLsToRetry to sendBulkRequests()
responseListRetried = sendBulkRequests(requestURLsToRetry)
How do I append responseListRetried it to original responseList to be returned so the next code can process hoping the data returned is correct.
I might need to send sendBulkRequests() multiple times until all correct API responses are received and above condition 2 is verified with no issues.