Retry in Python requests
<p>I have below needs for retry:</p>

<p>My Python script uses REQUESTS module to call API &amp; parse JSON response.</p>

<p>lately the API returns incomplete data like below</p>

<p>Incomplete data:</p>

<pre><code>  {
    offerInfo: {
      siteID: "001",
      language: "en_US",
      currency: "USD"
    },
    userInfo: {
      persona: {
        personaType: "OTHERS"
      },
      userId: "111"
    },
    offers: { }
  }
</code></pre>

<p>Complete data:</p>

<pre><code>  {
    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]
          }
       }
    }
  }
</code></pre>

<p>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 &amp; go to the next API URL.</p>

<p>I am trying with below code with session,but not sure how can I add the check in it ['offers']['Flight']</p>

<p>Note: There is no HTTP error while getting incomplete data returned from API ,so I have to rely on keys ['offers']['Flight'] </p>

<pre><code>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)
</code></pre>