7
我試圖在Python中實現請求重試。
它的工作方式與.get()
請求相似,但.post()
請求不會重試,無論狀態碼如何。我想用.post()
請求來使用它。如何使python .post()請求重試?
我的代碼:
from requests.packages.urllib3.util import Retry
from requests.adapters import HTTPAdapter
from requests import Session, exceptions
s = Session()
s.mount('http://', HTTPAdapter(max_retries=Retry(total=2, backoff_factor=1, status_forcelist=[ 500, 502, 503, 504, 521])))
r = s.get('http://httpstat.us/500')
r2 = s.post('http://httpstat.us/500')
因此,.get()
請求重試做和.post()
那些沒有。
怎麼了?
難道這就是像你期望的工作? GET請求不會損害數據,但可能會有多個「POST」。我還沒有通讀請求API文檔,但這聽起來是合理的,如果這是設計。 –