title: Wait for successful response from API Call
body: <p>I am using Yahoo Api, I have implemented random sleep method in addition to that I have added hard sleeps but still I am unable to figure how I can just wait or try again if I don't get a response at first attempt. </p>
  
  <p>For an example the code that I have put below, fails at some users, totally randomly. After it fails I take the url on my browser and it works like a charm. So my questions is why? and How can I resolve this? or can I improve this code to do do another request after a hard sleep (Only if thats a good approach)</p>
  
  <p>I have few more information which I forgot to add, I changed the code to get my http success code:</p>
  
  <pre><code>print urlobject.getcode()
  </code></pre>
  
  <p>and it returns 200, but no json, as some suggested this might be throttle.</p>
  
  <p><em>Note: I have removed my appid(Key) from the url</em></p>
  
  <pre><code># return the json question for given question id
  def returnJSONQuestion(questionId):
      randomSleep()
      url = 'http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=APPIDREMOVED8&amp;question_id={0}&amp;output=json'
      format_url = url.format(questionId)
      try:
          request = urllib2.Request(format_url)
          urlobject = urllib2.urlopen(request)
          time.sleep(10)
          jsondata = json.loads(urlobject.read().decode("utf-8"))
          print jsondata
      except urllib2.HTTPError, e:
          print e.code
          logging.exception("Exception")
      except urllib2.URLError, e:
          print e.reason
          logging.exception("Exception")
      except(json.decoder.JSONDecodeError,ValueError):
          print 'Question ID ' + questionId + ' Decode JSON has failed'
          logging.info("This qid didn't work " + questionId)
      return jsondata
  </code></pre>