I'm trying to implement requests retry in Python.
It works like charm with .get()
requests, but a .post()
request never retries, regardless of a status code. I'd like to use it with .post()
requests.
My code:
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')
So, the .get()
requests do retry and the .post()
ones do not.
What's wrong?
GET
requests won't harm data, but multiplePOST
might. I haven't read through the requests API documentation, but it sounds reasonable if this is by design. – Raylenerayless