Diagnose proxy failures before you retry.
Separate client, DNS, TCP, TLS, proxy authentication, target response, parsing, and validation. The same visible failure can require very different action.
Classify before retrying.
Record the phase, target, proxy product, route policy, attempt, status, exception, and elapsed time.
Retry safe transient failures with jitter.
Retries must have a hard attempt limit, exponential delay, random jitter, and a reason recorded for each attempt.
import random
import time
import requests
RETRYABLE = {429, 500, 502, 503, 504}
for attempt in range(4):
try:
response = requests.get(url, proxies=proxies, timeout=(10, 30))
if response.status_code not in RETRYABLE:
response.raise_for_status()
break
except (requests.ConnectTimeout, requests.ReadTimeout):
if attempt == 3:
raise
time.sleep(min(2 ** attempt + random.random(), 30))
Use separate connect and read budgets.
A short connect timeout detects unreachable routes. A read timeout must allow the target and expected object size enough time without leaving workers blocked indefinitely.
DNS, socket, and proxy reachability.
Handshake and certificate verification.
Time waiting for response data.
Total deadline across attempts and processing.
Log enough context without leaking credentials.
Sanitize proxy URLs and never write passwords to logs. Keep route policy, not secret values.
Questions before production.
Should a 407 rotate to another exit?
No. Fix credentials or plan access; changing exits does not repair authentication.
Are 403 and 429 proxy failures?
They are normally target responses. Review authorization, request behavior, and rate.
Should TLS verification be disabled?
No. Fix clock, CA, SNI, or certificate-chain problems instead.
Which requests are safe to retry?
Retry operations that are idempotent or explicitly protected by an idempotency mechanism.