Home > OS >  How to retry 'Connection aborted.', RemoteDisconnected('Remote end closed connection
How to retry 'Connection aborted.', RemoteDisconnected('Remote end closed connection

Time:01-05

def some_func(url):
    try:
        requests.get(url)
    except exception as e:
        # retry code here

I want to retry the request if the previous request gets a connection aborted error. How can I implement this?

CodePudding user response:

From the requests docs:

s = requests.Session()
a = requests.adapters.HTTPAdapter(max_retries=3)
s.mount('http://', a)
s.mount('https://', a)

def some_func(url):
    s.get(url)

For finer retry behaviour see urrlib3's doc on Retry.

  •  Tags:  
  • Related