I have below needs for retry:
My Python script uses REQUESTS module to call API & parse JSON response.
lately the API returns incomplete data like below
Incomplete data:
{
offerInfo: {
siteID: "001",
language: "en_US",
currency: "USD"
},
userInfo: {
persona: {
personaType: "OTHERS"
},
userId: "111"
},
offers: { }
}
Complete data:
{
offerInfo: {
siteID: "001",
language: "en_US",
currency: "USD"
},
userInfo: {
persona: {
personaType: "OTHERS"
},
userId: "111"
},
offers: {
Flight: [
{
offerDateRange: {
travelStartDate: [2016, 5, 7],
travelEndDate: [2016, 5, 11]
}
}
}
}
A complete response should have ['offers']['Flight'] keys in it ,if not my code should try to call the API N times before it gives up & go to the next API URL.
I am trying with below code with session,but not sure how can I add the check in it ['offers']['Flight']
Note: There is no HTTP error while getting incomplete data returned from API ,so I have to rely on keys ['offers']['Flight']
session = requests.Session()
session.mount("http://", requests.adapters.HTTPAdapter(max_retries=2))
session.mount("https://", requests.adapters.HTTPAdapter(max_retries=2))
try:
response = session.get(url=line,timeout=(connect_timeout,read_timeout),verify=False)
while True: ...
andbreak
when you have correct data or you tried too many times.