Does the request execute the retry method after some seconds?

here is my code.

import requests,time
proxies = {'http':''}

i = 0
a = requests.adapters.HTTPAdapter(max_retries=10)
s = requests.Session()
s.mount(url, a)
for x in xrange(1,1000):
    print x
        r= s.get(url,proxies=proxies)
        print r
    except Exception as ee:
        i = i + 1
        print ee
        print 'i=%s' % i


the proxy is a bit unsteady, so I set max_retries, but it still has some kind of exception, so is there some method to execute after some seconds on every try ??


source to share

1 answer

It's just requests

not possible with a library . However, you can use an external library like backoff .


provides a decorator and wraps it around your function. Sample code:

                      max_tries=10, interval=10)
def get_url(url):
    return requests.get(url)


The above code waits 10 seconds for the next retry on every exception requests.exceptions.RequestException

and it tries to execute 10 times as stated in max_tries




All Articles