def some_func(url):
try:
requests.get(url)
except exception as e:
# retry code here
如果前一個請求出現連接中止錯誤,我想重試該請求。我該如何實施?
uj5u.com熱心網友回復:
從請求檔案:
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)
對于更精細的重試行為看urrlib3的doc上Retry。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/406211.html
標籤:
