diff --git a/app/services/qualys_service.py b/app/services/qualys_service.py index a44d05a..d6ec397 100644 --- a/app/services/qualys_service.py +++ b/app/services/qualys_service.py @@ -625,14 +625,23 @@ def _refresh_all_agents_impl(db, mode="diff"): "preferences": {"limitResults": 100}, "filters": {"Criteria": criteria} }} - try: - r = requests.post( - f"{qualys_url}/qps/rest/2.0/search/am/hostasset", - json=payload, auth=(qualys_user, qualys_pass), - verify=False, timeout=600, proxies=proxies, - headers={"X-Requested-With": "PatchCenter", "Content-Type": "application/json"}) - except Exception as e: - return {"ok": False, "msg": f"page {stats['pages']}: {e}", **stats} + # Retry sur erreurs transitoires proxy/reseau (max 3 essais) + r = None + last_err = None + for attempt in range(3): + try: + r = requests.post( + f"{qualys_url}/qps/rest/2.0/search/am/hostasset", + json=payload, auth=(qualys_user, qualys_pass), + verify=False, timeout=600, proxies=proxies, + headers={"X-Requested-With": "PatchCenter", "Content-Type": "application/json"}) + break + except Exception as e: + last_err = e + import time as _t + _t.sleep(2 * (attempt + 1)) # backoff 2s, 4s + if r is None: + return {"ok": False, "msg": f"page {stats['pages']} apres 3 essais: {last_err}", **stats} if r.status_code != 200 or "SUCCESS" not in r.text: return {"ok": False, "msg": f"HTTP {r.status_code} page {stats['pages']}", **stats}