title: Adding callback function on each retry attempt using requests/urllib3
body: <p>I've implemented a retry mechanism to <code>requests</code> session using <a href="http://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry" rel="nofollow noreferrer"><code>urllib3.util.retry</code></a> as suggested both <a href="https://stackoverflow.com/questions/15431044/can-i-set-max-retries-for-requests-request">here</a> and <a href="https://stackoverflow.com/questions/49121365/implementing-retry-for-requests-in-python">here</a>.</p>
  <p>Now, I am trying to figure out what is the best way to add a callback function that will be called on every retry attempt.</p>
  <p>To explain myself even more, if either the <code>Retry</code> object or the requests <code>get</code> method had a way to add a callback function, it would have been great. Maybe something like:</p>
  <pre><code>import requests
  from requests.packages.urllib3.util.retry import Retry
  from requests.adapters import HTTPAdapter
  
  def retry_callback(url):
      print url   
  
  s = requests.Session()
  retries = Retry(total=5, status_forcelist=[ 500, 502, 503, 504 ])
  s.mount('http://', HTTPAdapter(max_retries=retries))
  
  url = 'http://httpstat.us/500'
  s.get(url, callback=retry_callback, callback_params=[url])
  </code></pre>
  <p>I know that for printing url I can use the logging, but this is only a simple example for a more complex use.</p>