如何重试'Connection aborted.',RemoteDisconnected('Remote end closed connection without response'错误

How to retry 'Connection aborted.', RemoteDisconnected('Remote end closed connection without response' error

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

如果之前的请求出现连接中止错误,我想重试该请求。我该如何实施?

来自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)

有关更精细的重试行为,请参阅 Retry 上的 urrlib3's doc